#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
//#define endl "\n"
using namespace std;
const int mod = 998244353;
const long long inf = 1000000000000000000;
const int sz = 3e5+5; /// mind the sz
ll L[80*sz], R[80*sz], st[80*sz], lazy[80*sz], cur = 1;
void ms(ll v){
if(!L[v]){L[v] = ++cur;}
if(!R[v]){R[v] = ++cur;}
}
void relax(ll v, ll l, ll r){
if(!lazy[v]){return ;}
st[v] = (r - l + 1);
if(l == r){
lazy[v] = 0;
return ;
}
ms(v);
lazy[L[v]] += lazy[v];
lazy[R[v]] += lazy[v];
lazy[v] = 0;
}
void update(ll v, ll tl, ll tr, ll l, ll r){
relax(v, tl, tr);
if(tl > r or tr < l){return ;}
if(tl >= l && tr <= r){
lazy[v] = 1;
relax(v, tl, tr);
return ;
}
ll tm = (tl + tr) >> 1;
if(tm < l){
if(!R[v]){R[v] = ++cur;}
update(R[v], tm+1, tr, l, r);
}
else if(tm >= r){
if(!L[v]){L[v] = ++cur;}
update(L[v], tl, tm, l, r);
}
else{
ms(v);
update(L[v], tl, tm, l, r);
update(R[v], tm+1, tr, l, r);
}
st[v] = st[L[v]] + st[R[v]];
}
ll get(ll v, ll tl, ll tr, ll l, ll r){
relax(v, tl, tr);
if(tl > r || tr < l){return 0;}
if(tl >= l && tr <= r){
return st[v];
}
ll tm = (tl + tr) >> 1;
if(tm < l){
if(!R[v]){R[v] = ++cur;}
return get(R[v], tm+1, tr, l, r);
}
else if(tm >= r){
if(!L[v]){L[v] = ++cur;}
return get(L[v], tl, tm, l, r);
}
else{
ms(v);
return get(L[v], tl, tm, l, r) + get(R[v], tm+1, tr, l, r);
}
}
void solve(){
ll q, i, j, l, r, x, c = 0, qt, n = 1e9;
cin>>q;
while(q--){
cin>>qt>>l>>r;
l += c;
r += c;
if(qt == 1){
ll res = get(1, 1, n, l, r);
c = res;
cout << res << endl;
}
else{
update(1, 1, n, l, r);
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//precomp();
ll tst=1;
//cin>>tst;
while(tst--){
solve();
}
}
/*
3
2 5 8
2 7 10
1 1 10
ok.
*/
Compilation message
apple.cpp: In function 'void solve()':
apple.cpp:81:11: warning: unused variable 'i' [-Wunused-variable]
81 | ll q, i, j, l, r, x, c = 0, qt, n = 1e9;
| ^
apple.cpp:81:14: warning: unused variable 'j' [-Wunused-variable]
81 | ll q, i, j, l, r, x, c = 0, qt, n = 1e9;
| ^
apple.cpp:81:23: warning: unused variable 'x' [-Wunused-variable]
81 | ll q, i, j, l, r, x, c = 0, qt, n = 1e9;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |