6-F Bovine winter passenger Cross array

Links: https://ac.nowcoder.com/acm/problem/201986
Source: Cattle-off network

Title Description

Q learned little new kind of magic, can cause damage to the enemy on the grid of N rows and M columns
The i-th magic can cross a region on the grid (i.e., xi and the first row and the second column yi) causing damage to the enemy zi for each of the squares in
Q small case now using a total of H times magic, you need to count all of the damage after casting is completed, as detailed output description
Reminder: the larger the scale of this problem input, use efficient input mode
1≤xi 1≤H≤500,000, Yi, zi and, N, M≤2000. 1 ≤xi ≤N,. 1 ≤yi ≤M

Enter a description:

The first line of three numbers N, M, H
Next H lines of three positive integer xi, yi, zi

Output Description:

To avoid large output, assuming total damage i-th row j-th column is subjected W ij of
You only need to output [sum] w ij of results (i + j) of 10 ^ 7 + 9 to modulo
Example 1

Entry

copy
5 5 5
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5

Export

copy
890

Explanation

Case of damage are:
1 3 4 5 6
3 2 5 6 7
4 5 3 7 8
5 6 7 4 9
6 7 8 9 5
Supplementary description:
890 = 1 * (1 + 1) + 3 * (1 + 2) + 4 * (1 + 3) + ... + 5 * (5 + 5), to give a total of 25 accumulated 890
 

 

 

 1 #include <bits/stdc++.h>
 2 #define dbg(x) cout << #x << "=" << x << endl
 3 #define eps 1e-8
 4 #define pi acos(-1.0)
 5 
 6 using namespace std;
 7 typedef long long LL;
 8 
 9 template<class T>inline void read(T &res)
10 {
11     char c;T flag=1;
12     while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
13     while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
14 }
15 
16 namespace _buff {
17     const size_t BUFF = 1 << 19;
18     char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
19     char getc() {
20         if (ib == ie) {
21             ib = ibuf;
22             ie = ibuf + fread(ibuf, 1, BUFF, stdin);
23         }
24         return ib == ie ? -1 : *ib++;
25     }
26 }
27 
28 int qread() {
29     using namespace _buff;
30     int ret = 0;
31     bool pos = true;
32     char c = getc();
33     for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
34         assert(~c);
35     }
36     if (c == '-') {
37         pos = false;
38         c = getc();
39     }
40     for (; c >= '0' && c <= '9'; c = getc()) {
41         ret = (ret << 3) + (ret << 1) + (c ^ 48);
42     }
43     return pos ? ret : -ret;
44 }
45 
46 const int maxn = 2007;
47 const int M = 1000000007;
48 
49 int n,m,h;
50 
51 int a[maxn], b[maxn];
52 int ab[maxn][maxn];
53 
54 int main()
55 {
56     scanf("%d %d %d",&n, &m, &h);
57 
58     int ans = 0;
59     int x, y, z;
60     while(h--) {
61         scanf("%d %d %d",&x,&y,&z);
62         a[x] += z;
63         b[y] += z;
64         ab[x][y] += z;
65     }
66     for(int i = 1; i <= n; ++i) {
67         for(int j = 1; j <= m; ++j) {
68             //printf("val[%d][%d]:%lld\n",i,j,a[i] + a[j] - ab[i][j]);
69             ans = (ans + (LL)(a[i] + b[j] - ab[i][j]) * (i+j) % M) % M;
70         }
71     }
72     printf("%d\n",(ans+M)%M);
73     return 0;
74 }
View Code

 

Guess you like

Origin www.cnblogs.com/orangeko/p/12319662.html