码迷,mamicode.com
首页 > 其他好文 > 详细

AtCoder 2394

时间:2019-08-04 00:59:20      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:hat   turn   scanf   tom   一个   mat   dimens   max   cst   

 

Problem Statement

 

On a two-dimensional plane, there are m lines drawn parallel to the x axis, and nlines 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<jn and 1≤k<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

 

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

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 轴的线,求这些线组成的矩形的面积和

 

根据组合数学的原理,可以发现每个x/y 各出现 2*i-n次,所以遍历统计一下就好了。 

 

技术图片
#include       <set>
#include       <map>
#include     <queue>
#include     <cmath>
#include    <cstdio>
#include    <cctype>
#include    <vector>
#include   <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int maxn = 1e5+5;

ll fast_pow(ll a,ll b,ll mod){
    ll ans = 1;
    while(b){
        if(b&1)
            ans = ans*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ans;
}

int main(){
    ll n, m;
    ll a, x=0, y=0;
    scanf("%lld%lld",&n,&m);

    for(int i=1;i<=n;i++){
        scanf("%lld",&a);
        x = (x+(2*i-n-1)*a)%mod;
    }
    for(int i=1;i<=m;i++){
        scanf("%lld",&a);
        y = (y+(2*i-m-1)*a)%mod;
    }
    printf("%lld\n",x*y%mod);
    return 0;
}
View Code

 

AtCoder 2394

标签:hat   turn   scanf   tom   一个   mat   dimens   max   cst   

原文地址:https://www.cnblogs.com/kongbb/p/11296832.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!