#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 = 1e5;
ll w, h, n;
ll x[MX], y[MX], a[MX], b[MX];
vector<vll> c, d, V, SUM;
bool inside(ll i, ll j) {return i>=0 && i<=w && j>=0 && j<=h;}
ll getV(ll i, ll X, ll Y) {
return a[i] - b[i]*max(0ll, max(abs(x[i]-X), abs(y[i]-Y)));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// input
IN(w,h,n);
RE(i,n) IN(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) {
ll r = (a[i]-1)/b[i];
ll mnj=max(y[i]-r,0ll);
ll mxj=min(h,y[i]+r);
REI(j,mnj,mxj) {
ll cr = abs(j-y[i]);
// increasing
ll bg = max(0ll, x[i] - r);
ll ed = x[i] - cr - 1;
if(ed >= 0) {
ll v = getV(i, bg, j);
d[bg][j] += b[i];
c[bg][j] += v - b[i]*bg;
d[ed+1][j] -= b[i];
c[ed+1][j] -= v - b[i]*bg;
}
// same
bg = max(0ll, 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 = getV(i, bg, j);
d[bg][j] -= b[i];
c[bg][j] += v + b[i]*bg;
d[ed+1][j] += b[i];
c[ed+1][j] -= v + b[i]*bg;
}
}
}
REP(i,1,w+1) RE(j,h+1) {
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;
IN(q);
RE(i,q) {
ll x1, x2, y1, y2;
IN(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);
OUTL((sm+area/2)/area);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
784 ms |
548344 KB |
Output is correct |
2 |
Correct |
84 ms |
4820 KB |
Output is correct |
3 |
Correct |
72 ms |
4088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
825 ms |
548344 KB |
Output is correct |
2 |
Correct |
75 ms |
4728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
79480 KB |
Output is correct |
2 |
Correct |
83 ms |
4424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
83620 KB |
Output is correct |
2 |
Correct |
77 ms |
4728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
901 ms |
554360 KB |
Output is correct |
2 |
Correct |
81 ms |
5628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
447 ms |
225528 KB |
Output is correct |
2 |
Correct |
78 ms |
4728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
211 ms |
84600 KB |
Output is correct |
2 |
Correct |
78 ms |
4984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
303 ms |
115832 KB |
Output is correct |
2 |
Correct |
77 ms |
4472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
38 ms |
8864 KB |
Execution killed with signal 11 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
39 ms |
8832 KB |
Execution killed with signal 11 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
208 ms |
169368 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
253 ms |
168440 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
211 ms |
170072 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
368 ms |
169068 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |