#include<iostream>
#define endl '\n'
#include<bits/stdc++.h>
using namespace std;
struct str
{
long long l=0, r=0, lazy=0, sum=0;
}tree[1000005];
long long last=2;
void update(long long le,long long ri,long long l,long long r,long long ind)
{
if(!tree[ind].l)tree[ind].l=last++;
if(!tree[ind].r)tree[ind].r=last++;
if(l<=le && ri<=r){tree[ind].lazy=1;}
if(tree[ind].lazy)
{
tree[ind].sum=(ri-le+1);
tree[tree[ind].l].lazy=1;
tree[tree[ind].r].lazy=1;
tree[ind].lazy=0;
}
if(l>ri || r<le)return;
if(l<=le && ri<=r)return;
long long mid=(le+ri)/2;
update(le,mid,l,r,tree[ind].l);
update(mid+1,ri,l,r,tree[ind].r);
tree[ind].sum=tree[tree[ind].l].sum+tree[tree[ind].r].sum;
// cout<<le<<" "<<ri<<" "<<tree[tree[ind].l].sum<<" "<<tree[tree[ind].r].sum<<" "<<tree[ind].sum<<endl;
}
long long query(long long le,long long ri,long long l,long long r,long long ind)
{
if(!tree[ind].l)tree[ind].l=last++;
if(!tree[ind].r)tree[ind].r=last++;
if(tree[ind].lazy)
{
tree[ind].sum=(ri-le+1);
tree[tree[ind].l].lazy=1;
tree[tree[ind].r].lazy=1;
tree[ind].lazy=0;
}
if(l<=le && ri<=r){return tree[ind].sum;}
if(l>ri || r<le)return 0;
long long mid=(le+ri)/2;
long long r1=0, r2=0;
if(tree[ind].l)r1=query(le,mid,l,r,tree[ind].l);
if(tree[ind].r)r2=query(mid+1,ri,l,r,tree[ind].r);
tree[ind].sum=tree[tree[ind].l].sum+tree[tree[ind].r].sum;
return r1+r2;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long i,j,t,l,r,m,c=0;
cin>>m;
for(i=0;i<m;i++)
{
cin>>t>>l>>r;
l+=c; r+=c;
if(t==2)
{
update(1,1000000002,l,r,1);
}
else{
c=query(1,1000000002,l,r,1);
cout<<c<<endl;
}
}
}
Compilation message
apple.cpp: In function 'int main()':
apple.cpp:75:17: warning: unused variable 'j' [-Wunused-variable]
75 | long long i,j,t,l,r,m,c=0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
12 ms |
6384 KB |
Output is correct |
5 |
Correct |
15 ms |
7820 KB |
Output is correct |
6 |
Correct |
15 ms |
7500 KB |
Output is correct |
7 |
Correct |
15 ms |
7756 KB |
Output is correct |
8 |
Runtime error |
89 ms |
64048 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |