#include<bits/stdc++.h>
#define ll int
using namespace std;
ll m,i,x,y,d,c,ans;
struct node{
node *le,*ri;
ll val,lazy,l,r;
void create(ll x,ll y){
val=0;
lazy=0;
l=x;
r=y;
le=NULL;
ri=NULL;
}
void fix(){
if(l==r){
if(lazy==1) val=1;
return;
}
ll mid=(l+r)/2;
if(le==NULL){
le=new node;
le->le=NULL;
le->ri=NULL;
le->l=l;
le->r=mid;
le->lazy=0;
le->val=0;
}
if(ri==NULL){
ri=new node;
ri->le=NULL;
ri->ri=NULL;
ri->l=mid+1;
ri->r=r;
ri->lazy=0;
ri->val=0;
}
if(lazy==1){
val=r-l+1;
le->lazy=1;
ri->lazy=1;
lazy=0;
}
}
ll query(ll x,ll y){
fix();
if(l>y || r<x) return 0;
if(l>=x && r<=y) return val;
return le->query(x,y)+ri->query(x,y);
}
void update(ll x,ll y){
fix();
if(l>y || r<x) return;
if(l>=x && r<=y){
val=r-l+1;
if(l!=r){
le->lazy=1;
ri->lazy=1;
}
return;
}
le->update(x,y);
ri->update(x,y);
val=le->val+ri->val;
}
} s;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> m;
s.create(1,1e9);
for(i=1;i<=m;i++){
cin >> d >> x >> y;
if(d==1){
ans=s.query(x+c,y+c);
cout << ans << "\n";
c=ans;
}
else{
s.update(x+c,y+c);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
8740 KB |
Output is correct |
5 |
Correct |
17 ms |
10588 KB |
Output is correct |
6 |
Correct |
17 ms |
10332 KB |
Output is correct |
7 |
Correct |
17 ms |
10588 KB |
Output is correct |
8 |
Correct |
173 ms |
77788 KB |
Output is correct |
9 |
Correct |
285 ms |
131924 KB |
Output is correct |
10 |
Correct |
289 ms |
148048 KB |
Output is correct |
11 |
Correct |
311 ms |
160340 KB |
Output is correct |
12 |
Correct |
331 ms |
166228 KB |
Output is correct |
13 |
Correct |
299 ms |
206240 KB |
Output is correct |
14 |
Correct |
296 ms |
208484 KB |
Output is correct |
15 |
Runtime error |
340 ms |
262144 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |