#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAXN=200005;
LL x[MAXN],y[MAXN],a[MAXN],b[MAXN];
LL dist(LL ax,LL ay,LL bx,LL by){
return max(abs(ax-bx),abs(ay-by));
}
LL ceiling(LL atas,LL bawah){
return (atas-1)/bawah+1;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
LL r,c,n,q,x1,y1,x2,y2;
cin >> c >> r >> n;
LL pref[r+5][c+5],prefA[c+5],prefB[c+5],sufA[c+5],sufB[c+5];
memset(pref,0,sizeof(pref));
memset(prefA,0,sizeof(prefA));
memset(prefB,0,sizeof(prefB));
memset(sufA,0,sizeof(sufA));
memset(sufB,0,sizeof(sufB));
for(LL i=1;i<=n;i++)cin >> y[i] >> x[i] >> a[i] >> b[i];
if(r==1){
for(LL i=1;i<=n;i++){
LL brp=ceiling(a[i],b[i]);
prefA[y[i]]+=a[i];
prefB[y[i]]+=b[i];
if(y[i]+brp<=c){
prefA[y[i]+brp]-=(a[i]-brp*b[i]);
prefB[y[i]+brp]-=b[i];
}
}
for(LL i=1;i<=c;i++){
prefA[i]+=(prefA[i-1]-prefB[i-1]);
prefB[i]+=prefB[i-1];
}
for(LL i=1;i<=n;i++){
LL brp=ceiling(a[i],b[i]);
sufA[y[i]]+=a[i];
sufB[y[i]]+=b[i];
if(y[i]-brp>=1){
sufA[y[i]-brp]-=(a[i]-brp*b[i]);
sufB[y[i]-brp]-=b[i];
}
}
for(LL i=c;i>=1;i--){
sufA[i]+=(sufA[i+1]-sufB[i+1]);
sufB[i]+=sufB[i+1];
}
for(LL i=1;i<=c;i++)prefA[i]+=sufA[i];
for(LL i=1;i<=n;i++)prefA[y[i]]-=a[i];
for(LL i=1;i<=c;i++)prefA[i]+=prefA[i-1];
cin >> q;
while(q--){
cin >> y1 >> x1 >> y2 >> x2;
LL bagi=(prefA[y2]-prefA[y1-1])/(y2-y1+1);
LL sisa=(prefA[y2]-prefA[y1-1])%(y2-y1+1);
if(sisa>=ceiling(y2-y1+1,2))bagi++;
cout << bagi << '\n';
}
return 0;
}
for(LL i=1;i<=r;i++){
for(LL j=1;j<=c;j++){
for(LL k=1;k<=n;k++)pref[i][j]+=max(0LL,a[k]-b[k]*dist(i,j,x[k],y[k]));
}
}
for(LL i=1;i<=r;i++){
for(LL j=1;j<=c;j++){
pref[i][j]+=pref[i][j-1]+pref[i-1][j]-pref[i-1][j-1];
}
}
cin >> q;
while(q--){
cin >> y1 >> x1 >> y2 >> x2;
LL bagi=(pref[x2][y2]-pref[x1-1][y2]-pref[x2][y1-1]+pref[x1-1][y1-1])/((x2-x1+1)*(y2-y1+1));
LL sisa=(pref[x2][y2]-pref[x1-1][y2]-pref[x2][y1-1]+pref[x1-1][y1-1])%((x2-x1+1)*(y2-y1+1));
if(sisa>=ceiling((x2-x1+1)*(y2-y1+1),2))bagi++;
cout << bagi << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
195 ms |
196088 KB |
Output is correct |
2 |
Correct |
81 ms |
4728 KB |
Output is correct |
3 |
Correct |
76 ms |
3960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
196088 KB |
Output is correct |
2 |
Correct |
85 ms |
4732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
315 ms |
20376 KB |
Output is correct |
2 |
Correct |
80 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
315 ms |
24824 KB |
Output is correct |
2 |
Correct |
82 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
326 ms |
198272 KB |
Output is correct |
2 |
Correct |
87 ms |
5368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
81140 KB |
Output is correct |
2 |
Correct |
82 ms |
4856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
462 ms |
22520 KB |
Output is correct |
2 |
Correct |
86 ms |
3048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
439 ms |
45764 KB |
Output is correct |
2 |
Correct |
80 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
438 ms |
204760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
454 ms |
204828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1057 ms |
26612 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1067 ms |
26360 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1069 ms |
26880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1047 ms |
26540 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |