• AtCoder 2394


    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:

    sample1-1

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

    sample1-2

    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
    ",x*y%mod);
        return 0;
    }
    View Code
  • 相关阅读:
    JDBC
    Listener监听器
    Filter过滤器
    Jstl标签库
    el表达式
    Ajax技术
    数据交换格式之
    MVC模式
    函数
    二维数组练习
  • 原文地址:https://www.cnblogs.com/kongbb/p/11296832.html
Copyright © 2020-2023  润新知