#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[10000005];
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;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
13 ms |
6348 KB |
Output is correct |
5 |
Correct |
16 ms |
7640 KB |
Output is correct |
6 |
Correct |
15 ms |
7360 KB |
Output is correct |
7 |
Correct |
16 ms |
7608 KB |
Output is correct |
8 |
Correct |
125 ms |
58032 KB |
Output is correct |
9 |
Correct |
269 ms |
100512 KB |
Output is correct |
10 |
Correct |
261 ms |
111272 KB |
Output is correct |
11 |
Correct |
266 ms |
119616 KB |
Output is correct |
12 |
Correct |
268 ms |
123364 KB |
Output is correct |
13 |
Correct |
234 ms |
143728 KB |
Output is correct |
14 |
Correct |
237 ms |
145088 KB |
Output is correct |
15 |
Runtime error |
363 ms |
262148 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |