#include <bits/stdc++.h>
using namespace std;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define RE(a,b) REP(a,0,b)
#define RE1(a,b) REP(a,1,b+1)
#define REI(a,b,c) REP(a,b,c+1)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz size()
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
template<class T> void IN(T& a) {cin>>a;}
template<class T, class... L> void IN(T& a, L&... b) {IN(a); IN(b...);}
template<class T> void OUT(const T& a) {cout<<a;}
template<class T, class... L> void OUT(const T& a, const L&... b) {OUT(a); OUT(b...);}
template<class... T> void OUTL(const T&... a) {OUT(a..., '\n');}
const int MX = 3e5;
int w, h, n;
int x[MX], y[MX], a[MX], b[MX];
vector<vll> c, d, V, SUM;
int getV(int i, int X, int Y) {
return a[i] - b[i]*max(abs(x[i]-X), abs(y[i]-Y));
}
int main() {
// input
scanf("%d%d%d", &w, &h, &n);
RE(i,n) scanf("%d%d%d%d", &x[i], &y[i], &a[i], &b[i]), x[i]--, y[i]--;
c.assign(w+1,vll(h+1,0));
d.assign(w+1,vll(h+1,0));
V.assign(w+1,vll(h+1,0));
SUM.assign(w+1,vll(h+1,0));
RE(i,n) {
int r = (a[i]-1)/b[i];
int mnj=max(y[i]-r,0);
int mxj=min(h-1,y[i]+r);
REI(j,mnj,mxj) {
int cr = abs(j-y[i]);
// increasing
int bg = max(0, x[i] - r);
int ed = x[i] - cr - 1;
if(ed >= 0) {
ll v = (ll)getV(i, bg, j) - (ll)b[i]*(ll)bg;
d[bg][j] += b[i];
c[bg][j] += v;
d[ed+1][j] -= b[i];
c[ed+1][j] -= v;
}
// same
bg = max(0, x[i] - cr);
ed = min(w-1, x[i] + cr);
ll v = getV(i, bg, j);
c[bg][j] += v;
c[ed+1][j] -= v;
// decreasing
bg = x[i] + cr + 1;
ed = min(w-1, x[i] + r);
if(bg < w) {
ll v = (ll)getV(i, bg, j) + (ll)b[i]*(ll)bg;;
d[bg][j] -= b[i];
c[bg][j] += v;
d[ed+1][j] += b[i];
c[ed+1][j] -= v;
}
}
}
REP(i,1,w) RE(j,h) {
c[i][j] += c[i-1][j];
d[i][j] += d[i-1][j];
}
RE(i,w) RE(j,h) V[i][j] = c[i][j] + (ll)i*d[i][j];
RE(i,w) SUM[i][0] = 0;
RE(i,h) SUM[0][i] = 0;
RE(i,w) RE(j,h) SUM[i+1][j+1] = SUM[i+1][j] + SUM[i][j+1] - SUM[i][j] + V[i][j];
// anser queries
int q;
scanf("%d", &q);
RE(i,q) {
int x1, x2, y1, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x1--; y1--;
ll sm = SUM[x2][y2] - SUM[x1][y2] - SUM[x2][y1] + SUM[x1][y1];
ll area = abs(x2-x1)*abs(y2-y1);
printf("%lld\n",(sm+area/2)/area);
}
}
Compilation message
nuclearia.cpp: In function 'int main()':
nuclearia.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
40 | scanf("%d%d%d", &w, &h, &n);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
41 | RE(i,n) scanf("%d%d%d%d", &x[i], &y[i], &a[i], &b[i]), x[i]--, y[i]--;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:97:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
97 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
nuclearia.cpp:100:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
100 | scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
729 ms |
548344 KB |
Output is correct |
2 |
Correct |
99 ms |
2804 KB |
Output is correct |
3 |
Correct |
90 ms |
2424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
737 ms |
548472 KB |
Output is correct |
2 |
Correct |
98 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
79480 KB |
Output is correct |
2 |
Correct |
104 ms |
2944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
83652 KB |
Output is correct |
2 |
Correct |
112 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
913 ms |
550520 KB |
Output is correct |
2 |
Correct |
112 ms |
3192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
474 ms |
222072 KB |
Output is correct |
2 |
Correct |
102 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
81400 KB |
Output is correct |
2 |
Correct |
126 ms |
3064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
326 ms |
112376 KB |
Output is correct |
2 |
Correct |
95 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1130 ms |
553848 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1102 ms |
553932 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1105 ms |
82592 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1104 ms |
82168 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1105 ms |
83024 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
82552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |