#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
struct Node {
int sum, lazy, tl, tr, l, r;
Node() : sum(0), lazy(0), l(-1), r(-1) {}
};
const int MAXN = 123456;
Node st[64 * MAXN];
int cnt = 2;
void push(int v) {
if (st[v].lazy) {
st[v].sum = st[v].tr - st[v].tl + 1;
int mid = (st[v].tl + st[v].tr) / 2;
if (st[v].l == -1) {
st[v].l = cnt++;
st[st[v].l].tl = st[v].tl;
st[st[v].l].tr = mid;
}
if (st[v].r == -1) {
st[v].r = cnt++;
st[st[v].r].tl = mid + 1;
st[st[v].r].tr = st[v].tr;
}
st[st[v].l].lazy = st[st[v].r].lazy = 1;
st[v].lazy = 0;
}
}
void upd(int v, int l, int r) {
push(v);
if (l == st[v].tl && r == st[v].tr) {
st[v].lazy = 1;
push(v);
} else {
int mid = (st[v].tl + st[v].tr) / 2;
if (st[v].l == -1) {
st[v].l = cnt++;
st[st[v].l].tl = st[v].tl;
st[st[v].l].tr = mid;
}
if (st[v].r == -1) {
st[v].r = cnt++;
st[st[v].r].tl = mid + 1;
st[st[v].r].tr = st[v].tr;
}
if (l > mid) upd(st[v].r, l, r);
else if (r <= mid) upd(st[v].l, l, r);
else {
upd(st[v].l, l, mid);
upd(st[v].r, mid + 1, r);
}
push(st[v].l);
push(st[v].r);
st[v].sum =
st[st[v].l].sum + st[st[v].r].sum;
}
}
int get(int v, int l, int r) {
push(v);
if (l == st[v].tl && r == st[v].tr)
return st[v].sum;
else {
int mid = (st[v].tl + st[v].tr) / 2;
if (st[v].l == -1) {
st[v].l = cnt++;
st[st[v].l].tl = st[v].tl;
st[st[v].l].tr = mid;
}
if (st[v].r == -1) {
st[v].r = cnt++;
st[st[v].r].tl = mid + 1;
st[st[v].r].tr = st[v].tr;
}
if (l > mid) return get(st[v].r, l, r);
else if (r <= mid) return get(st[v].l, l, r);
else
return get(st[v].l, l, mid) +
get(st[v].r, mid + 1, r);
}
}
int main() {
iostream::sync_with_stdio(false);
if (fopen("hi.inp", "r")) {
freopen("hi.inp", "r", stdin);
// freopen("hi.out", "w", stdout);
}
cin.tie(0);
int m;
cin >> m;
st[1].sum = 0;
st[1].lazy = 0;
st[1].tl = 1;
st[1].tr = 1e9;
int c = 0;
FOR(_, 0, m) {
int d, x, y;
cin >> d >> x >> y;
if (d == 1) {
c = get(1, x + c, y + c);
cout << c << '\n';
} else upd(1, x + c, y + c);
}
db(cnt)
return 0;
}
Compilation message
apple.cpp: In function 'int main()':
apple.cpp:117:5: error: 'db' was not declared in this scope
117 | db(cnt)
| ^~
apple.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | freopen("hi.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~