UPC - ### (combination regimen)

Learning is like rowing upstream

UPC-###

Title 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.

translation

On a two-dimensional plane, on a parallel line is drawn parallel to the x-axis and m, n and parallel lines parallel to the y axis. A straight line parallel to the x axis, from the bottom up to the i-th parallel to the straight line x Y i is represented, equally, from the left to the right by the i-th parallel to the straight line x, x i is represented.
For each of these straight lines by a rectangular siege, they determined area, and outputs all of ten . 9 total area after taking over and +7.
That is, for every four satisfying 1≤i <j≤n, 1≤k <l≤m the (i, j, k, l ) is determined for each X = X I , X = X J , Y = Y K and Y = Y L , and the area consisting of, and in 10 . 9 take +7.
Constraints
-10 . 9 ≤x . 1 <... <X n- ≦ 10 . 9
-10 . 9 ≤Y . 1 <... <Y m ≦ 10 . 9
X I and Y I are integers

Entry

Input is given from Standard Input in the following format:
n m
x1 x2 … xn
y1 y2 … ym

translation

Input from the standard input, the following format:
nm
X . 1 X 2 ... X n-
Y . 1 Y 2 ... Y m

Export

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

translation

Output of ten . 9 all area after modulo +7.

Sample Input

3 3
1 3 4
1 3 6

Sample Output

60

Hint

The figure below illustrates this input:
Here Insert Picture Description
The following is the total of the rectangular area A 9, B, ..., as shown as 60. The figure below illustrates this input:
Here Insert Picture Description

Analytical thinking
Here Insert Picture Description
Summarize what is a formula
1 a < b 4 1 c < d 4 ( b a ) ( d c ) \sum_{1≤a<b≤4}\sum_{1≤c<d≤4}\left ( b-a \right )\left ( d-c \right )\,
If you still do not understand how one thing, took over the motion picture speak for themselves
Here Insert Picture Description
and then with the delicious cheese mathematical formula can get open
1 a < b 4 ( b a ) 1 c < d 4 ( d c ) \sum_{1≤a<b≤4}\left ( b-a \right )*\sum_{1≤c<d≤4}\left ( d-c \right )\,

After it is calculated according to this formula all the area
, but it is regular, painting at the map to find it
Here Insert Picture Description
OK, attach codes
AC time to! !

#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
#include<string>
#include<math.h>
#include<stdio.h>
#pragma GCC optimize(2)
#define Swap(a,b)  a ^= b ^= a ^= b
using namespace std;
typedef long long ll;
const int MAXN=10010;
const ll long_inf=9223372036854775807;
const int int_inf=2147483647;
inline ll read() {
	ll c=getchar(),Nig=1,x=0;
	while(!isdigit(c)&&c!='-')c=getchar();
	if(c=='-')Nig=-1,c=getchar();
	while(isdigit(c))x=((x<<1)+(x<<3))+(c^'0'),c=getchar();
	return Nig*x;
}
ll N=1e9+7;
ll x[100005],y[100005];
int main() {
	ll a,b;
	cin>>a>>b;
	for(ll i=0; i<a; i++)
		x[i]=read();
	for(ll j=0; j<b; j++)
		y[j]=read();
	ll sumx=0,sumy=0;
	for(ll i=1; i<a; i++) {
		sumx+=(((((a-i)%N)*i)%N)*((x[i]-x[i-1])%N));
		sumx%=N;
	}
	for(ll i=1; i<b; i++) {
		sumy+=(((((b-i)%N)*i)%N)*((y[i]-y[i-1])%N));
		sumy%=N;
	}
	cout<<(sumx*sumy)%N<<endl;
}

If not (ni) * i traveled all the words, but will time out, so this place has played the role of optimization, to avoid double counting.

There is a road ground for the tracks, Boundless Learning bitter for the boat.

By- wheel month

Published 32 original articles · won praise 12 · views 1192

Guess you like

Origin blog.csdn.net/qq_35339563/article/details/104162870