#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
vector<vector<long long int>> A, B;
long long int D[2500005];
long long int E[2500005];
long long int F[2500005];
long long int G[2500005];
array<long long int, 4> C[200005];
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int W, H;
cin >> W >> H;
if(H==1) {
int i, j;
int N;
cin >> N;
for(i=0;i<N;i++) {
ll a, b, c, d;
cin >> a >> b >> c >> d;
a--, b--;
ll k = c/d;
ll l = max(0LL, a-k);
ll r = min((ll)W-1, a+k);
F[l] += d;
G[l] += c - d*a;
F[a+1] -= d;
G[a+1] -= c - d*a;
F[a+1] += -d;
G[a+1] += c+d*a;
F[r+1] -= -d;
G[r+1] -= c+d*a;
}
ll sum1 = 0, sum2 = 0;
for(i=0;i<W;i++) {
sum1 += F[i], sum2 += G[i];
__int128 v = (__int128) i * sum1 + sum2;
D[i] = v;
//cout << D[i] << ' ';
}
//cout << '\n';
for(i=0;i<W;i++) E[i] = (i ? E[i-1] : 0) + D[i];
int Q;
cin >> Q;
while(Q--) {
ll a, b, c, d;
cin >> a >> b >> c >> d;
a--, b-- ,c--, d--;
ll val = E[c] - (a?E[c-1]:0);
ll x = c-a+1;
ll y = val / x;
if(2*(val%x)>=x) y++;
cout << y << '\n';
}
return 0;
}
A.resize(W);
B.resize(W);
int i, j;
for(i=0;i<W;i++) {
A[i].resize(H);
B[i].resize(H);
}
int N;
cin >> N;
for(i=0;i<N;i++) {
cin >> C[i][0] >> C[i][1] >> C[i][2] >> C[i][3];
C[i][0]--, C[i][1]--;
for(j=0;j<W;j++) {
for(register int k = 0; k < H; k++) {
A[j][k] += max(0LL, C[i][2] - max(abs(j-C[i][0]),abs(k-C[i][1])) * C[i][3]);
}
}
}
for(i=0;i<W;i++) {
for(j=0;j<H;j++) {
B[i][j] = (i?B[i-1][j]:0) + (j?B[i][j-1]:0) - ((long long int)i*j?B[i-1][j-1]:0) + A[i][j];
}
}
int Q;
cin >> Q;
while(Q--) {
long long int a, b, c, d;
cin >> a >> b >> c >> d;
a--, b--, c--, d--;
long long int val = B[c][d] - (a?B[a-1][d]:0) - (b?B[c][b-1]:0) + (a*b?B[a-1][b-1]:0);
//cout << val << '\n
long long int x = (c-a+1)* (d-b+1);
long long int y = val / x;
if(2*(val % x) >= x) y++;
cout << y << '\n';
}
}
Compilation message
nuclearia.cpp: In function 'int main()':
nuclearia.cpp:20:16: warning: unused variable 'j' [-Wunused-variable]
20 | int i, j;
| ^
nuclearia.cpp:82:76: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
82 | B[i][j] = (i?B[i-1][j]:0) + (j?B[i][j-1]:0) - ((long long int)i*j?B[i-1][j-1]:0) + A[i][j];
| ~~~~~~~~~~~~~~~~^~
nuclearia.cpp:91:77: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
91 | long long int val = B[c][d] - (a?B[a-1][d]:0) - (b?B[c][b-1]:0) + (a*b?B[a-1][b-1]:0);
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
39892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
40008 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
263 ms |
39840 KB |
Output is correct |
2 |
Correct |
53 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
231 ms |
39592 KB |
Output is correct |
2 |
Correct |
55 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
131 ms |
40676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
81 ms |
18436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
330 ms |
41780 KB |
Output is correct |
2 |
Correct |
61 ms |
2876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
603 ms |
57420 KB |
Output is correct |
2 |
Correct |
53 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
200 ms |
79840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
194 ms |
79876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1097 ms |
39764 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
39644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
40404 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1092 ms |
39844 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |