#include<bits/stdc++.h>
using namespace std;
const int lmt = 1e5 + 5;
struct Nodo{
int v, ls, rs;
bool lazy;
Nodo(){
v = lazy = ls = rs = 0;
}
};
Nodo st[lmt * 64 * 2];
int t=2;
void update(Nodo &A, int v){
if(A.ls==0){
A.ls = t++;
A.rs = t++;
}
if(!A.lazy) return;
A.v = v;
st[A.ls].lazy = st[A.rs].lazy = true;
A.lazy=false;
return;
}
int query(int tmp, int l, int r, int ini = 0, int fin = 1e9){
Nodo &A = st[tmp];
update(A, (fin-ini)+1);
if(ini>r || fin<l) return 0;
if(ini>=l && fin<=r){
return A.v;
}
int mit = (ini+fin)/2;
return query(A.ls, l, r, ini, mit) + query(A.rs, l, r, mit+1, fin);
}
void insert(int tmp, int l, int r, int ini = 0, int fin = 1e9){
Nodo &A = st[tmp];
update(A, (fin-ini)+1);
if(ini>r || fin<l) return;
if(ini>=l && fin<=r){
A.v = (fin-ini)+1;
A.lazy = -1;
return;
}
int mit = (ini+fin)/2;
insert(A.ls, l, r, ini, mit);
insert(A.rs, l, r, mit+1, fin);
A.v = st[A.ls].v + st[A.rs].v;
return;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int q; cin>>q;
long long c = 0;
while(q--){
int z, x, y;
cin>>z>>x>>y;
x+=c; y+=c;
if(z==1){
cout << (c = query(1,x,y)) << "\n";
}else{
insert(1,x,y);
}
}
return 0;
}
Compilation message
apple.cpp: In constructor 'Nodo::Nodo()':
apple.cpp:8:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
8 | v = lazy = ls = rs = 0;
| ~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
200680 KB |
Output is correct |
2 |
Correct |
85 ms |
200592 KB |
Output is correct |
3 |
Correct |
83 ms |
200636 KB |
Output is correct |
4 |
Correct |
94 ms |
200800 KB |
Output is correct |
5 |
Correct |
95 ms |
200880 KB |
Output is correct |
6 |
Correct |
98 ms |
200908 KB |
Output is correct |
7 |
Correct |
104 ms |
200880 KB |
Output is correct |
8 |
Correct |
166 ms |
201668 KB |
Output is correct |
9 |
Correct |
267 ms |
202876 KB |
Output is correct |
10 |
Correct |
276 ms |
202764 KB |
Output is correct |
11 |
Correct |
268 ms |
202784 KB |
Output is correct |
12 |
Correct |
279 ms |
202840 KB |
Output is correct |
13 |
Correct |
255 ms |
203240 KB |
Output is correct |
14 |
Correct |
252 ms |
203412 KB |
Output is correct |
15 |
Correct |
315 ms |
203360 KB |
Output is correct |
16 |
Correct |
321 ms |
203312 KB |
Output is correct |
17 |
Correct |
251 ms |
203208 KB |
Output is correct |
18 |
Correct |
252 ms |
203188 KB |
Output is correct |
19 |
Correct |
325 ms |
203464 KB |
Output is correct |
20 |
Correct |
323 ms |
203284 KB |
Output is correct |