#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;
const int treesize = sz*32*4;
const int inf = 1e9+7;
const intt infl = 1e18;
const int mod = 1e9+7;
const ld eps = 1e-9;
struct node{
int lchild, rchild, res, lz;
};
int last = 1;
node st[treesize];
void extend(int ind){
if ( st[ind].lchild ) return;
st[ind].lchild = ++last;
st[ind].rchild = ++last;
}
void relax(int l, int r, int in){
if ( !st[in].lz ) return;
st[in].res = r-l+1;
if ( l != r ){
extend(in);
st[st[in].lchild].lz = st[st[in].rchild].lz = 1;
}
st[in].lz = 0;
}
void update(int a, int b, int l, int r, int in){
relax(l, r, in);
if ( b < l or r < a ) return;
if ( a <= l and r <= b ){
// cout << l << " " << r << " " << in << endl;
st[in].lz = 1;
relax(l, r, in);
// cout << st[in].res << endl;
return;
}
int mid = (l+r)>>1;
extend(in);
update(a, b, l, mid, st[in].lchild);
update(a, b, mid+1, r, st[in].rchild);
st[in].res = st[st[in].lchild].res + st[st[in].rchild].res;
}
int getans(int a, int b, int l, int r, int in){
// cout << a << " " << b << "-> "<< l << " " << r << " : " << in << endl;
relax(l, r, in);
if ( b < l or r < a ) return 0;
if ( a <= l and r <= b ){
// cout << l << " " << r << " " << in << " = " << st[in].res << endl;
return st[in].res;
}
extend(in);
int mid = (l+r)>>1;
return getans(a, b, l, mid, st[in].lchild) + getans(a, b, mid+1, r, st[in].rchild);
}
int i,j;
void solve(){
int q;
cin >> q;
int c = 0;
int n = 1e9+5;
while ( q-- ){
int t, l, r;
cin >> t >> l >> r;
l += c;
r += c;
if ( t == 1 ){
c = getans(l, r, 1, n, 1);
cout << c << endl;
}
else{
update(l, r, 1, n, 1);
}
}
}
signed main(){
fastio;
int t=1;
// cin >> t;
while ( t-- ){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |