#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define mid (l+r>>1)
const int MX=1e9;
struct seg {
int l, r, ans;
bool lz;
seg *lc, *rc;
seg(int l=1, int r=MX+1): l(l), r(r), ans(0), lz(0), lc(NULL), rc(NULL) {}
void pull() {
ans = 0;
if(lc) ans += lc->ans;
if(rc) ans += rc->ans;
}
void apply() {
ans = r-l; lz = 1;
}
void push() {
if(r-l==1) return;
if(!lc) lc = new seg(l, mid);
if(!rc) rc = new seg(mid, r);
if(!lz) return;
lc->apply();
rc->apply();
lz = 0;
}
void upd(int s, int e) {
push();
if(s<=l && r<=e) {
apply();
return;
}
if(s<mid) lc->upd(s, e);
if(e>mid) rc->upd(s, e);
pull();
}
int get(int s, int e) {
push();
if(s<=l && r<=e) return ans;
int res=0;
if(s<mid) res += lc->get(s, e);
if(e>mid) res += rc->get(s, e);
return res;
}
};
int32_t main() {
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
seg *ds = new seg();
int q;
cin >> q;
int c=0;
while(q--) {
int d, x, y;
cin >> d >> x >> y;
x += c; y += c+1;
if(d==1) cout << (c=ds->get(x,y)) << '\n';
else ds->upd(x, y);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |