#include <bits/stdc++.h>
#define intt long long
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<intt,intt>
#define ld long double
// #define int intt
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) x.begin(), x.end()
using namespace std;
const int sz = (1e5+5)*100;
const int inf = 1e9+7;
const intt infl = 1e18;
const int mod = 1e9+7;
const ld eps = 1e-9;
int st[sz], L[sz], R[sz], lz[sz];
int last = 1;
void extend(int in){
if ( L[in] ) return;
L[in] = ++last;
R[in] = ++last;
assert(last < sz);
}
void relax(int l, int r, int in){
if ( !lz[in] ) return;
st[in] = r-l+1;
if ( l != r ) extend(in);
lz[L[in]] = lz[R[in]] = 1;
lz[in] = 0;
}
void update(int a, int b, int l, int r, int in){
// cout << "in " << in << " [" << l << " " << r << "]" << endl;
// cout << L[in] << " " << R[in] << endl;
relax(l, r, in);
if ( b < l or r < a ) return;
if ( a <= l and r <= b ){
lz[in] = 1;
relax(l, r, in);
return;
}
int mid = (l+r)>>1;
extend(in);
update(a, b, l, mid, L[in]);
update(a, b, mid+1, r, R[in]);
st[in] = st[L[in]]+st[R[in]];
// cout << l << " " << r << " : " << st[in] << endl;
}
int getans(int a, int b, int l, int r, int in){
// cout << a << " " << b << " : " << l << " " << r << endl;
if ( !in ) return 0;
relax(l, r, in);
if ( b < l or r < a ) return 0;
if ( a <= l and r <= b ){
// cout << "res = " << st[in] << endl;
return st[in];
}
int mid = (l+r)>>1;
return (L[in] ? getans(a, b, l, mid, L[in]) : 0)+
(R[in] ? getans(a, b, mid+1, r, R[in]) : 0);
}
int i,j;
void solve(){
int n = 1e9+1, c = 0;
int t;
cin >> t;
while (t--){
int d, x, y;
cin >> d >> x >> y;
x += c;
y += c;
assert(x<=y);
if ( d == 1 ){
int res = getans(x, y, 1, n, 1);
cout << res << endl;
c = res;
}
else{
update(x, y, 1, n, 1);
}
}
}
signed main(){
fastio;
int t=1;
// cin >> t;
while ( t-- ){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |