//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
vector<vl> off, sl, sm, d1, d2;
vector<vl> offC, slC, offSlC, slSlC;
int main() {
int w, h, n;
scanf("%d %d %d", &w, &h, &n);
off.resize(h+1); sl.resize(h+1), sm.resize(h+1);
d1.resize(h+3), d2.resize(h+3), offC.resize(h+3), slC.resize(h+3);
offSlC.resize(h+3), slSlC.resize(h+3);
for (int i = 0; i <= h; i++)
off[i].resize(w+3), sl[i].resize(w+3), sm[i].resize(w+3);
for (int i = 0; i <= h+2; i++) {
d1[i].resize(w+3), d2[i].resize(w+3);
offC[i].resize(w+3), slC[i].resize(w+3);
offSlC[i].resize(w+3), slSlC[i].resize(w+3);
}
for (int i = 0; i < n; i++) {
ll x, y, a, b;
scanf("%lld %lld %lld %lld", &x, &y, &a, &b);
ll l = max(1ll, x - a / b), r = min((ll)w, x + a / b);
ll c = max(1ll, y - a / b), d = min((ll)h, y + a / b);
if (x-abs(y-c) < 1ll) {
d1[y-x+1][2] -= b;
offSlC[c][2] -= b;
offSlC[y-x+1][2] += b;
} else
d1[c][x-abs(y-c)+1] -= b;
if (x-abs(y-d) < 1ll) {
d2[x+y-1][2] -= b;
offSlC[x+y][2] -= b;
offSlC[d+1][2] += b;
} else
d2[d][x-abs(y-d)+1] -= b;
if (x+abs(y-d) > (ll)w) {
//d1[w+y-x+1][w+2] += b;
} else
d1[d+1][x+abs(y-d)+2] += b;
if (x+abs(y-c) > (ll)w) {
//d2[x+y-w-1][w+2] += b;
} else
d2[c-1][x+abs(y-c)+2] += b;
offC[c][l] += a;
offC[d+1][l] -= a;
offC[c][r+1] -= a;
offC[d+1][r+1] += a;
slC[c][l] -= abs(y-c) * b;
slC[c+1][l] += abs(y-c) * b + b;
slC[y+1][l] -= 2 * b;
slC[d+1][l] += abs(y-d) * b + b;
slC[d+2][l] -= abs(y-d) * b;
slC[c][r+1] += abs(y-c) * b;
slC[c+1][r+1] -= abs(y-c) * b + b;
slC[y+1][r+1] += 2 * b;
slC[d+1][r+1] -= abs(y-d) * b + b;
slC[d+2][r+1] += abs(y-d) * b;
for (ll j = c; j <= d; j++) {
ll lo = max(1ll, x-abs(y-j));
sl[j][l] -= b * (lo-l);
sl[j][l+1] += b * (lo-l+1);
ll hi = min((ll)w, x+abs(y-j));
sl[j][r+1] += b*(r-hi+1);
sl[j][r+2] -= b*(r-hi);
}
}
//cerr << "\n";
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
d1[i][j] += d1[i-1][j-1];
offC[i][j] += offC[i-1][j];
slC[i][j] += slC[i-1][j];
offSlC[i][j] += offSlC[i-1][j];
slSlC[i][j] += slSlC[i-1][j];
//cerr << i << " " << j << " " << slC[i][j] << "\n";
}
}
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++) {
slC[i][j] += slC[i-1][j];
slSlC[i][j] += slSlC[i-1][j];
//cerr << i << " " << j << " " << slC[i][j] << "\n";
}
for (int i = h-1; i > 0; i--)
for (int j = 1; j <= w; j++)
d2[i][j] += d2[i+1][j-1];
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
sl[i][j] += d1[i][j] + d2[i][j] + offSlC[i][j] + slSlC[i][j];
off[i][j] += offC[i][j] + slC[i][j];
off[i][j] += off[i][j-1];
sl[i][j] += sl[i][j-1];
}
for (int j = 1; j <= w; j++)
sl[i][j] += sl[i][j-1];
for (int j = 1; j <= w; j++)
sm[i][j] = sm[i-1][j] + sm[i][j-1] - sm[i-1][j-1] + sl[i][j] + off[i][j];
}
int q; ni(q);
while (q--) {
ll x1, y1, x2, y2;
scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
ll ans = sm[y2][x2] - sm[y1-1][x2] - sm[y2][x1-1] + sm[y1-1][x1-1];
x1 = (x2-x1+1) * (y2-y1+1);
if ((ans % x1) * 2 >= x1)
prl(ans / x1 + 1);
else
prl(ans / x1);
}
return 0;
}
Compilation message
nuclearia.cpp: In function 'int main()':
nuclearia.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &w, &h, &n);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld %lld", &x, &y, &a, &b);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:9:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define ni(n) scanf("%d", &(n))
~~~~~^~~~~~~~~~~~
nuclearia.cpp:134:9: note: in expansion of macro 'ni'
int q; ni(q);
^~
nuclearia.cpp:137:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
963 ms |
587460 KB |
Output is correct |
2 |
Correct |
103 ms |
3832 KB |
Output is correct |
3 |
Correct |
90 ms |
3360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
558 ms |
587564 KB |
Output is correct |
2 |
Correct |
100 ms |
3704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
211 ms |
177660 KB |
Output is correct |
2 |
Correct |
98 ms |
3704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
612 ms |
238320 KB |
Output is correct |
2 |
Correct |
100 ms |
3704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
770 ms |
590492 KB |
Output is correct |
2 |
Correct |
107 ms |
3964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
384 ms |
238524 KB |
Output is correct |
2 |
Correct |
100 ms |
3548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
383 ms |
182264 KB |
Output is correct |
2 |
Correct |
105 ms |
3832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
307 ms |
156216 KB |
Output is correct |
2 |
Correct |
97 ms |
3476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
934 ms |
590308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
887 ms |
590300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1089 ms |
178056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
177772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
188092 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1077 ms |
178036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |