#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll inf = 1e18;
struct segtree{
struct node{
ll sm, lazy_assign, lazy_add, mx, mn;
node(){
sm = 0LL, mx = 0LL, mn = 0LL, lazy_assign = -inf, lazy_add = 0LL;
}
void calc(node a, node b){
sm = a.sm+b.sm;
mx = max(a.mx, b.mx);
mn = min(a.mn, b.mn);
}
};
int k;
node v[524288];
segtree(int n){
k = 1;
while(k <= n) k*=2; k*=2;
}
void chmx(int l, int r, int nd, int a, int b, ll x, ll ex, bool tt){
if(a > r || b < l || (tt ? ex:v[nd].mn+ex) >= x){
if(tt){
v[nd].lazy_assign = ex;
v[nd].lazy_add = 0LL;
v[nd].sm = (b-a+1)*ex;
v[nd].mn = ex;
v[nd].mx = ex;
}
else{
v[nd].lazy_add+=ex;
v[nd].sm+=(b-a+1)*ex;
v[nd].mn+=ex;
v[nd].mx+=ex;
}
return;
}
if(a >= l && b <= r && (tt ? ex:v[nd].mx+ex) < x){
v[nd].lazy_assign = x;
v[nd].lazy_add = 0LL;
v[nd].sm = (b-a+1)*x;
v[nd].mn = x;
v[nd].mx = x;
return;
}
int md = (a+b)/2;
if(!tt){
ex+=v[nd].lazy_add;
if(v[nd].lazy_assign != -inf){
ex+=v[nd].lazy_assign;
tt = 1;
}
}
v[nd].lazy_add = 0LL;
v[nd].lazy_assign = -inf;
chmx(l, r, 2*nd, a, md, x, ex, tt);
chmx(l, r, 2*nd+1, md+1, b, x, ex, tt);
if(2*nd+1 < k) v[nd].calc(v[2*nd], v[2*nd+1]);
}
void chmx(int l, int r, ll x){
chmx(l, r, 1, 0, k/2-1, x, 0LL, 0);
}
void add(int l, int r, int nd, int a, int b, ll x, ll ex, bool tt){
if(a > r || b < l){
if(tt){
v[nd].lazy_assign = ex;
v[nd].lazy_add = 0LL;
v[nd].sm = (b-a+1)*ex;
v[nd].mn = ex;
v[nd].mx = ex;
}
else{
v[nd].lazy_add+=ex;
v[nd].sm+=(b-a+1)*ex;
v[nd].mn+=ex;
v[nd].mx+=ex;
}
return;
}
if(a >= l && b <= r){
if(tt){
v[nd].lazy_assign = ex;
v[nd].lazy_add = 0LL;
v[nd].sm = (b-a+1)*ex;
v[nd].mn = ex;
v[nd].mx = ex;
}
else{
v[nd].lazy_add+=ex;
v[nd].sm+=(b-a+1)*ex;
v[nd].mn+=ex;
v[nd].mx+=ex;
}
v[nd].lazy_add+=x;
v[nd].sm+=(b-a+1)*x;
v[nd].mn+=x;
v[nd].mx+=x;
return;
}
int md = (a+b)/2;
if(!tt){
ex+=v[nd].lazy_add;
if(v[nd].lazy_assign != -inf){
ex+=v[nd].lazy_assign;
tt = 1;
}
}
v[nd].lazy_add = 0LL;
v[nd].lazy_assign = -inf;
add(l, r, 2*nd, a, md, x, ex, tt);
add(l, r, 2*nd+1, md+1, b, x, ex, tt);
if(2*nd+1 < k) v[nd].calc(v[2*nd], v[2*nd+1]);
}
void add(int l, int r, ll x){
add(l, r, 1, 0, k/2-1, x, 0LL, 0);
}
ll sum(int l, int r, int nd, int a, int b, ll ex, bool tt){
if(a > r || b < l){
if(tt){
v[nd].lazy_assign = ex;
v[nd].lazy_add = 0LL;
v[nd].sm = (b-a+1)*ex;
v[nd].mn = ex;
v[nd].mx = ex;
}
else{
v[nd].lazy_add+=ex;
v[nd].sm+=(b-a+1)*ex;
v[nd].mn+=ex;
v[nd].mx+=ex;
}
return 0LL;
}
if(a >= l && b <= r){
if(tt){
v[nd].lazy_assign = ex;
v[nd].lazy_add = 0LL;
v[nd].sm = (b-a+1)*ex;
v[nd].mn = ex;
v[nd].mx = ex;
}
else{
v[nd].lazy_add+=ex;
v[nd].sm+=(b-a+1)*ex;
v[nd].mn+=ex;
v[nd].mx+=ex;
}
return v[nd].sm;
}
int md = (a+b)/2;
if(!tt){
ex+=v[nd].lazy_add;
if(v[nd].lazy_assign != -inf){
ex+=v[nd].lazy_assign;
tt = 1;
}
}
v[nd].lazy_add = 0LL;
v[nd].lazy_assign = -inf;
ll rt = sum(l, r, 2*nd, a, md, ex, tt) + sum(l, r, 2*nd+1, md+1, b, ex, tt);
if(2*nd+1 < k) v[nd].calc(v[2*nd], v[2*nd+1]);
return rt;
}
ll sum(int l, int r){
return sum(l, r, 1, 0, k/2-1, 0LL, 0);
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, q; cin >> n >> m >> q;
segtree seg(n);
while(q--){
int tt; cin >> tt;
if(tt == 1){
int l, r, c; ll k; cin >> l >> r >> c >> k; l--, r--;
seg.add(l, r, k);
}
else if(tt == 2){
int l, r; ll k; cin >> l >> r >> k; l--, r--;
seg.add(l, r, -k);
seg.chmx(0, seg.k/2-1, 0);
}
else{
int a; ll b; cin >> a >> b; a--;
cout << (seg.sum(a, a) >= b ? 1:0) << "\n";
}
}
}
Compilation message
foodcourt.cpp: In constructor 'segtree::segtree(int)':
foodcourt.cpp:25:9: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
25 | while(k <= n) k*=2; k*=2;
| ^~~~~
foodcourt.cpp:25:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
25 | while(k <= n) k*=2; k*=2;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
20844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
20844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
110 ms |
21996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
479 ms |
22220 KB |
Output is correct |
2 |
Correct |
396 ms |
21996 KB |
Output is correct |
3 |
Correct |
516 ms |
21996 KB |
Output is correct |
4 |
Correct |
350 ms |
22124 KB |
Output is correct |
5 |
Correct |
355 ms |
22124 KB |
Output is correct |
6 |
Correct |
471 ms |
21996 KB |
Output is correct |
7 |
Correct |
106 ms |
21996 KB |
Output is correct |
8 |
Correct |
107 ms |
21996 KB |
Output is correct |
9 |
Correct |
427 ms |
22124 KB |
Output is correct |
10 |
Correct |
435 ms |
22232 KB |
Output is correct |
11 |
Correct |
495 ms |
21996 KB |
Output is correct |
12 |
Correct |
503 ms |
21996 KB |
Output is correct |
13 |
Correct |
449 ms |
21996 KB |
Output is correct |
14 |
Correct |
496 ms |
21996 KB |
Output is correct |
15 |
Correct |
548 ms |
22124 KB |
Output is correct |
16 |
Correct |
545 ms |
21996 KB |
Output is correct |
17 |
Correct |
514 ms |
22036 KB |
Output is correct |
18 |
Correct |
660 ms |
21996 KB |
Output is correct |
19 |
Correct |
512 ms |
22124 KB |
Output is correct |
20 |
Correct |
513 ms |
22124 KB |
Output is correct |
21 |
Correct |
524 ms |
21996 KB |
Output is correct |
22 |
Correct |
552 ms |
22252 KB |
Output is correct |
23 |
Correct |
534 ms |
21996 KB |
Output is correct |
24 |
Correct |
554 ms |
22164 KB |
Output is correct |
25 |
Correct |
366 ms |
22252 KB |
Output is correct |
26 |
Correct |
376 ms |
22124 KB |
Output is correct |
27 |
Execution timed out |
1077 ms |
21948 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
20844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
91 ms |
22216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
20844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
20844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |