AtCoder:井井井 / ###(数学)

传送门

D - 井井井 / ###


Time limit : 2sec / Memory limit : 256MB

Score : 500 points

Problem Statement

On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y=yi. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x=xi.

For every rectangle that is formed by these lines, find its area, and print the total area modulo 109+7.

That is, for every quadruple (i,j,k,l) satisfying 1i<jn and 1k<lm, find the area of the rectangle formed by the lines x=xix=xjy=yk and y=yl, and print the sum of these areas modulo 109+7.

Constraints

  • 2n,m105
  • −109x1<<xn109
  • −109y1<<ym109
  • xi and yi are integers.

Input

Input is given from Standard Input in the following format:

n m
x1 x2  xn
y1 y2  ym

Output

Print the total area of the rectangles, modulo 109+7.


Sample Input 1

Copy
3 3
1 3 4
1 3 6

Sample Output 1

Copy
60

The following figure illustrates this input:

sample1-1

The total area of the nine rectangles A, B, ..., I shown in the following figure, is 60.

sample1-2


Sample Input 2

Copy
6 5
-790013317 -192321079 95834122 418379342 586260100 802780784
-253230108 193944314 363756450 712662868 735867677

Sample Output 2

Copy
835067060
题意:给定n条平行于y轴的线x[1~n],和m条平行于x轴的线y[1~n],计算x[i],x[j]和y[k],y[l]组成的矩形面积之和,1<=x思路:每次固定两个y线,枚举所有x线二元组,发现x线和y线可以分开计算,即AtCoder:井井井 / ###(数学)_第1张图片

# include 
using namespace std;
 
typedef long long LL;
const LL mod = 1e9+7;
LL x[100003], y[100003];
int main()
{
    int n, m;
    scanf("%d%d",&n,&m);
    for(int i=0; i




你可能感兴趣的:(数论)