#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cassert>
using namespace std;
typedef long long ll;
const int Log=22, pot=(1<<Log);
struct tournament{
ll t[pot*2];
pair < ll, ll > prop[pot*2];
void propagate(int &x, int &range){
if(!prop[x].first && !prop[x].second){
return;
}
t[x]+=prop[x].first*range+prop[x].second*(range*(range-1)/2);
if(x<pot){
prop[x*2].first+=prop[x].first;
prop[x*2].second+=prop[x].second;
prop[x*2+1].first+=prop[x].first+prop[x].second*(range/2);
prop[x*2+1].second+=prop[x].second;
}
prop[x].first=0;
prop[x].second=0;
}
void update(int x, ll val){
for(; x>0; x/=2){
t[x]+=val;
}
}
void update2(int L, int D, int x, int l, int d, pair < ll, ll > val){
int range=D-L+1;
propagate(x, range);
if(L>=l && D<=d){
update(x, val.first*range+val.second*(range*(range-1)/2));
if(x<pot){
prop[x*2].first+=val.first;
prop[x*2].second+=val.second;
prop[x*2+1].first+=val.first+val.second*(range/2);
prop[x*2+1].second+=val.second;
}
return;
}
if((L+D)/2>=l){
update2(L, (L+D)/2, x*2, l, min(d, (L+D)/2), val);
val.first+=val.second*(min((L+D)/2, d)-l+1);
}
if((L+D)/2+1<=d){
update2((L+D)/2+1, D, x*2+1, max(l, (L+D)/2+1), d, val);
}
}
ll query(int L, int D, int x, int l, int d){
int range=D-L+1;
propagate(x, range);
if(L>=l && D<=d){
return t[x];
}
ll lijeva=0, desna=0;
if((L+D)/2>=l){
lijeva=query(L, (L+D)/2, x*2, l, d);
}
if((L+D)/2+1<=d){
desna=query((L+D)/2+1, D, x*2+1, l, d);
}
return lijeva+desna;
}
};
tournament T;
int main(){
int h, w;
scanf("%d%d", &w, &h);
bool p=0;
if(h>w){
swap(h, w);
}
assert(h==1);
int n, q;
scanf("%d", &n);
ll a, b, c, d;
int kol;
int l, r;
pair < ll, ll > val;
for(int i=0; i<n; i++){
scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
a--;
b--;
if(!p){
swap(a, b);
}
kol=c/d;
l=b-kol;
r=b;
if(l>-1){
val={c%d, d};
}
else{
val={c%d-l*d, d};
l=0;
}
// cout << "upd " << val.first << ' ' << val.second << endl;
T.update2(0, pot-1, 1, l, r, val);
l=b+1;
r=b+kol;
r=min(r, w-1);
val={c-d, -d};
if(l<=r){
T.update2(0, pot-1, 1, l, r, val);
}
}
/* for(int i=0; i<w; i++){
cout << T.query(0, pot-1, 1, i, i) << ' ';
}
cout << endl;*/
scanf("%d", &q);
for(int i=0; i<q; i++){
scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
a--;
b--;
c--;
d--;
if(!p){
swap(a, b);
swap(c, d);
}
printf("%lld\n", (ll)round((long double)T.query(0, pot-1, 1, b, d)/(d-b+1)));
// printf("%lld\n", (ll)T.query(0, pot-1, 1, b, d));
}
return 0;
}
Compilation message
nuclearia.cpp: In function 'int main()':
nuclearia.cpp:79:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
79 | scanf("%d%d", &w, &h);
| ~~~~~^~~~~~~~~~~~~~~~
nuclearia.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
nuclearia.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:122:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
122 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
nuclearia.cpp:124:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
124 | scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
63 ms |
134332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
134668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
183 ms |
266692 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
185 ms |
266692 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
472 ms |
174400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
392 ms |
151020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
186 ms |
266628 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
180 ms |
266592 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1062 ms |
174264 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1071 ms |
174732 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
183 ms |
266748 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
185 ms |
266628 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
181 ms |
266668 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
194 ms |
266696 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |