#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cassert>
using namespace std;
typedef long long ll;
const int maxn=2500000;
ll range[maxn*2];
ll najl[maxn*2];
ll pref[maxn+1];
void precompute(){
for(int i=maxn; i<maxn*2; i++){
range[i]=1;
najl[i]=i-maxn;
}
for(int i=maxn-1; i>0; i--){
range[i]=range[i*2]*2;
najl[i]=najl[i*2];
}
}
struct tournament{
pair < ll, ll > prop[maxn*2];
void propagate(int &x){
if(!prop[x].first && !prop[x].second){
return;
}
if(x<maxn){
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[x]/2);
prop[x*2+1].second+=prop[x].second;
}
}
void update2(int l, int d, pair < ll, ll > val){
ll L=l;
d++;
int x;
ll val1;
for(l+=maxn, d+=maxn; l<d; l>>=1, d>>=1){
if(l&1){
x=l++;
val1=val.first+val.second*(najl[x]-L);
prop[x].first+=val1;
prop[x].second+=val.second;
}
if(d&1){
x=--d;
val1=val.first+val.second*(najl[x]-L);
prop[x].first+=val1;
prop[x].second+=val.second;
}
}
}
void resi(){
for(int i=1; i<maxn*2; i++){
propagate(i);
}
}
};
tournament T;
/*
struct tournament1{
int pot;
vector < tournament > t;
tournament1(int sz1, int sz2){
pot=sz1;
tournament T(sz2);
for(int i=0; i<pot*2; i++){
t.push_back(T);
}
}
void update(int l, int d, int l2, int d2, pair < ll, ll > val){
d++;
for(l+=pot, d+=pot; l<d; l>>=1, d>>=1){
if(l&1){
t[l++].update2(l2, d2, val);
}
if(d&1){
}
}
}
};
*/
int main(){
precompute();
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);
int a, b, c, d;
int kol;
int l, r;
pair < ll, ll > val;
for(int i=0; i<n; i++){
scanf("%d%d%d%d", &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(l, r, val);
l=b+1;
r=b+kol;
r=min(r, w-1);
val={c-d, -d};
if(l<=r){
T.update2(l, r, val);
}
}
T.resi();
for(int i=0; i<w; i++){
pref[i+1]=pref[i]+T.prop[i+maxn].first;
}
/* for(int i=0; i<w; i++){
cout << T.query(i, i) << ' ';
}
cout << endl;*/
scanf("%d", &q);
ll sol, dij, res;
for(int i=0; i<q; i++){
scanf("%d%d%d%d", &a, &b, &c, &d);
if(!p){
swap(a, b);
swap(c, d);
}
sol=pref[d]-pref[b-1];
dij=d-b+1;
res=sol/dij;
if(sol%dij>=(dij+1)/2){
res++;
}
printf("%lld\n", res);
// printf("%lld\n", (ll)T.query(0, pot-1, 1, b, d));
}
return 0;
}
Compilation message
nuclearia.cpp: In function 'int main()':
nuclearia.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | scanf("%d%d", &w, &h);
| ~~~~~^~~~~~~~~~~~~~~~
nuclearia.cpp:104:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
nuclearia.cpp:110:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
110 | scanf("%d%d%d%d", &a, &b, &c, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:144:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
144 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
nuclearia.cpp:147:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
147 | scanf("%d%d%d%d", &a, &b, &c, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
176472 KB |
Output is correct |
2 |
Correct |
145 ms |
81088 KB |
Output is correct |
3 |
Correct |
141 ms |
80652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
176300 KB |
Output is correct |
2 |
Correct |
145 ms |
81144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
120 ms |
159108 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
121 ms |
159160 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
220 ms |
178528 KB |
Output is correct |
2 |
Correct |
151 ms |
81344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
195 ms |
120332 KB |
Output is correct |
2 |
Correct |
150 ms |
81048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
121 ms |
159128 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
128 ms |
159188 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
432 ms |
178720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
448 ms |
178748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
121 ms |
159056 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
123 ms |
159184 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
121 ms |
159044 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
128 ms |
159104 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |