#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct node{
int l=-1,r=-1;
int sum = 0;
int rem = 0;
};
vector<node>seg(1);
void push(int u){
if(seg[u].l==-1){
seg[u].l=seg.size();
seg.emplace_back();
}
if(seg[u].r==-1){
seg[u].r=seg.size();
seg.emplace_back();
}
seg[seg[u].l].rem+=seg[u].rem/2;
seg[seg[u].r].rem+=seg[u].rem/2;
seg[seg[u].l].sum+=seg[u].rem/2;
seg[seg[u].r].sum+=seg[u].rem/2;
seg[u].rem=0;
}
void update(int l,int r,int u,int lx,int rx){
if(l>=lx && r<=rx){
seg[u].rem+=r-l+1;
seg[u].sum=r-l+1;
return;
}
if(l>rx || r<lx){
return;
}
int mid = (l+r)/2;
push(u);
update(l,mid,seg[u].l,lx,rx);
update(mid+1,r,seg[u].r,lx,rx);
seg[u].sum=seg[seg[u].l].sum+seg[seg[u].r].sum;
}
int get(int l,int r,int u,int lx,int rx){
if(l>=lx && r<=rx){
return seg[u].sum;
}
if(l>rx || r<lx){
return 0;
}
int mid = (l+r)/2;
push(u);
return get(l,mid,seg[u].l,lx,rx)+get(mid+1,r,seg[u].r,lx,rx);
}
void solve(){
int q;
cin>>q;
int c = 0;
int s = (1<<30)-1;
while(q--){
int type,l,r;
cin>>type>>l>>r;
l--,r--;
l+=c;
r+=c;
if(type==2){
update(0,s,0,l,r);
}
else {
c = get(0,s,0,l,r);
cout<<c<<endl;
}
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
// ll t;cin>>t;while(t--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |