井井井 / ###(AtCoder-2394)

Problem Description

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 1≤i<j≤n and 1≤k<l≤m, find the area of the rectangle formed by the lines x=xi, x=xj, y=yk and y=yl, and print the sum of these areas modulo 109+7.

Constraints

  • 2≤n,m≤105
  • −109≤x1<…<xn≤109
  • −109≤y1<…<ym≤109
  • 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.

Example

Sample Input 1

3 3
1 3 4
1 3 6

Sample Output 1

60
The following figure illustrates this input:

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

Sample Input 2

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

Sample Output 2

835067060

题意:在一个二维坐标系上,有 n 条平行 y 轴的线和 m 条平行于 x 轴的线,求这些线组成的矩形的面积和

思路:

根据题意,可以推出:\sum_{1\leqslant i< j\leqslant n }\sum_{1\leqslant k< l\leqslant m }(x_j-x_i)*(y_l-y_k)

化简后有:(\sum_{1\leqslant i< j\leqslant n }(x_j-x_i))*(\sum_{1\leqslant k< l\leqslant m }(y_l-y_k))

那么问题就转化成求 \sum_{1\leqslant i< j\leqslant n }(x_j-x_i) 和 \sum_{1\leqslant k< l\leqslant m }(y_l-y_k)

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
LL x[N],y[N];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%lld",&x[i]);
    for(int j=1;j<=m;j++)
        scanf("%lld",&y[j]);

    LL sx=0;
    for(int i=1;i<=n;i++){
        sx=(sx+x[i]*(i-1))%MOD;
        sx=(sx-x[i]*(n-i))%MOD;
    }
    LL sy=0;
    for(int i=1;i<=m;i++){
        sy=(sy+y[i]*(i-1))%MOD;
        sy=(sy-y[i]*(m-i))%MOD;
    }
    LL res=(sx*sy)%MOD;
    printf("%lld\n",res);

    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值