#include <bits/stdc++.h>
using namespace std ;
const int MAX = 2e5 + 10 ;
int arr[MAX] ;
int q ;
int tree[MAX * 30] , lazy[MAX * 30] ;
int lft[MAX * 30] , rht[MAX * 30] ;
int id = 1 ;
int Left(int node)
{
if(!lft[node])
lft[node] = ++id ;
return lft[node] ;
}
int Right(int node)
{
if(!rht[node])
rht[node] = ++id ;
return rht[node] ;
}
void update(int node , int l , int r , int from , int to , bool flag)
{
if(from > r || to < l)
return ;
flag |= lazy[node] ;
if(l >= from && r <= to)
{
tree[node] = r-l+1 , lazy[node] = 1 ;
return ;
}
int mid = (l + r) >> 1 ;
update(Left(node) , l , mid , from , to , flag) ;
update(Right(node) , mid+1 , r , from , to , flag) ;
tree[node] = tree[Left(node)] + tree[Right(node)] ;
if(flag)
tree[node] = r-l+1 ;
}
int query(int node , int l , int r , int from , int to , bool flag)
{
if(from > r || to < l)
return 0 ;
flag |= lazy[node] ;
if(l >= from && r <= to)
{
if(flag)
return (r-l+1) ;
else
return tree[node] ;
}
int mid = (l + r) >> 1 ;
int x = query(Left(node) , l , mid , from , to , flag) ;
int y = query(Right(node) , mid+1 , r , from , to , flag) ;
return (x + y) ;
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>q ;
int cnt = 0 ;
while(q--)
{
int ty , l , r ;
cin>>ty>>l>>r ;
l += cnt , r += cnt ;
if(ty == 1)
{
int ans = query(1 , 1 , 1e9 , l , r , 0) ;
cnt = ans ;
cout<<ans<<"\n" ;
}
else
update(1 , 1 , 1e9 , l , r , 0) ;
}
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
1828 KB |
Output is correct |
5 |
Correct |
11 ms |
2132 KB |
Output is correct |
6 |
Correct |
9 ms |
2132 KB |
Output is correct |
7 |
Correct |
9 ms |
2212 KB |
Output is correct |
8 |
Correct |
78 ms |
14908 KB |
Output is correct |
9 |
Correct |
180 ms |
25608 KB |
Output is correct |
10 |
Correct |
167 ms |
28384 KB |
Output is correct |
11 |
Correct |
161 ms |
30372 KB |
Output is correct |
12 |
Correct |
177 ms |
31300 KB |
Output is correct |
13 |
Correct |
145 ms |
36480 KB |
Output is correct |
14 |
Correct |
154 ms |
36920 KB |
Output is correct |
15 |
Correct |
232 ms |
66988 KB |
Output is correct |
16 |
Correct |
220 ms |
67528 KB |
Output is correct |
17 |
Correct |
158 ms |
38188 KB |
Output is correct |
18 |
Correct |
151 ms |
38128 KB |
Output is correct |
19 |
Correct |
224 ms |
69008 KB |
Output is correct |
20 |
Correct |
223 ms |
69044 KB |
Output is correct |