#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int nmax = 25e5;
int **s;
i64 sum[nmax + 1];
struct aintnod {
i64 s, r;
} aint[4 * nmax + 1];
void update (int nod, int x, int y, int st, int dr, i64 a, i64 b) {
if (st <= x && y <= dr) {
aint[nod].s += a + (x - st) * b;
aint[nod].r += b;
return ;
}
int mij = (x + y) / 2;
if (st <= mij)
update(2 * nod, x, mij, st, dr, a, b);
if (mij < dr)
update(2 * nod + 1, mij + 1, y, st, dr, a, b);
}
void build (int nod, int x, int y) {
if (x == y) {
sum[x] = aint[nod].s;
return ;
}
int mij = (x + y) / 2;
update(2 * nod, x, mij, x, mij, aint[nod].s, aint[nod].r);
update(2 * nod + 1, mij + 1, y, mij + 1, y, aint[nod].s + aint[nod].r * (mij + 1 - x), aint[nod].r);
build(2 * nod, x, mij);
build(2 * nod + 1, mij + 1, y);
}
int main () {
int w, h, n;
cin >> w >> h >> n;
if (h != 1) {
s = new int*[w + 1];
for (int i = 0; i <= w; ++ i)
s[i] = new int[h + 1]();
for (int i = 1; i <= n; ++ i) {
int x, y, a, b;
cin >> x >> y >> a >> b;
for (int j = 1; j <= w; ++ j)
for (int k = 1; k <= h; ++ k) {
int c = max(0LL, a - 1LL * b * max(abs(x - j), abs(y - k)));
s[j][k] += c;
}
}
for (int i = 1; i <= w; ++ i)
for (int j = 1; j <= h; ++ j)
s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
} else if (h == 1) {
for (int i = 1; i <= n; ++ i) {
int x, y, a, b;
cin >> x >> y >> a >> b;
int pfin = min(w, x + a / b);
update(1, 1, w, x, pfin, a, -b);
pfin = max(1, x - a / b);
if (pfin <= x - 1)
update(1, 1, w, pfin, x - 1, a - b * (x - pfin), b);
}
build(1, 1, w);
for (int i = 1; i <= w; ++ i)
sum[i] += sum[i - 1];
int q;
cin >> q;
for (int i = 1; i <= q; ++ i) {
int a, b, x, y;
cin >> a >> b >> x >> y;
i64 total = sum[x] - sum[a - 1];
i64 arie = (x - a + 1);
i64 r = total / arie;
if (total % arie >= (arie + 1) / 2) ++ r;
cout << r << "\n";
}
exit(0);
}
int q;
cin >> q;
for (int i = 1; i <= q; ++ i) {
int a, b, x, y;
cin >> a >> b >> x >> y;
i64 total = s[x][y] - s[a - 1][y] - s[x][b - 1] + s[a - 1][b - 1];
i64 arie = (x - a + 1) * (y - b + 1);
i64 r = total / arie;
if (total % arie >= (arie + 1) / 2) ++ r;
cout << r << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
151292 KB |
Output is correct |
2 |
Correct |
471 ms |
3040 KB |
Output is correct |
3 |
Correct |
466 ms |
2900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
151280 KB |
Output is correct |
2 |
Correct |
463 ms |
2912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
304 ms |
10296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
332 ms |
10752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
768 ms |
153588 KB |
Output is correct |
2 |
Correct |
510 ms |
3380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
700 ms |
43856 KB |
Output is correct |
2 |
Correct |
474 ms |
3112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
904 ms |
11676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1072 ms |
21836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1077 ms |
152980 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1079 ms |
153064 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1062 ms |
10240 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1071 ms |
10240 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1074 ms |
10240 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1063 ms |
10240 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |