#include <bits/stdc++.h>
using namespace std;
#define inf 0x3F3F3F3F
struct Node
{
int val = 0, l = -1, r = -1;
};
const int MXN = 1e5 + 5;
const int mod = 1e9 + 7;
const int LOG = 31;
int m, c = 1;
Node st[MXN * LOG * 2];
int lz[MXN * LOG * 2];
void relax(int l, int r, int x)
{
if (lz[x] == -1) return;
st[x].val = (r - l + 1);
if (l == r)
{
lz[x] = -1;
return;
}
lz[(st[x].l == -1 ? st[x].l = ++c : st[x].l)] = lz[(st[x].r == -1 ? st[x].r = ++c : st[x].r)] = lz[x];
lz[x] = -1;
}
void make(int l, int r, int x, int lx, int rx)
{
relax(l, r, x);
if (l > rx || r < lx) return;
if (l >= lx && r <= rx)
{
lz[x] = 1;
relax(l, r, x);
return;
}
int mid = (l + r) >> 1;
make(l, mid, (st[x].l == -1 ? st[x].l = ++c : st[x].l), lx, rx);
make(mid + 1, r, (st[x].r == -1 ? st[x].r = ++c : st[x].r), lx, rx);
st[x].val = (st[x].l != -1 ? st[st[x].l].val : 0) + (st[x].r != -1 ? st[st[x].r].val : 0);
}
int get(int l, int r, int x, int lx, int rx)
{
if (l > rx || r < lx) return 0;
relax(l, r, x);
if (l >= lx && r <= rx) return st[x].val;
int mid = (l + r) >> 1;
return (st[x].l != -1 ? get(l, mid, st[x].l, lx, rx) : 0) + (st[x].r != -1 ? get(mid + 1, r, st[x].r, lx, rx) : 0);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> m;
for (int i = 0; i < MXN * LOG; i++) lz[i] = -1;
int p = 0;
while (m--)
{
int t;
cin >> t;
if (t == 1)
{
int l, r;
cin >> l >> r;
l += p, r += p;
cout << (p = get(1, 1e9, 1, l, r)) << '\n';
}
else
{
int l, r;
cin >> l >> r;
l += p, r += p;
make(1, 1e9, 1, l, r);
}
}
}
Compilation message
Compilation timeout while compiling apple