#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
struct node {
node *l, *r;
int cnt;
node() : l(nullptr), r(nullptr), cnt(0) {}
};
void getch(node& here, int l, int r) {
if (here.l == nullptr) {
here.l = new node();
here.r = new node();
}
if (here.cnt == r - l) {
here.l->cnt = here.cnt / 2;
here.l->cnt = here.cnt / 2;
}
}
void upd(node& here, int l, int r, int a, int b) {
if (l >= b || r <= a) return;
if (a <= l && r <= b) {
here.cnt = r - l;
return;
}
int m = (l + r) / 2;
getch(here, l, r);
upd(*here.l, l, m, a, b);
upd(*here.r, m, r, a, b);
here.cnt = here.l->cnt + here.r->cnt;
}
int cnt(node& here, int l, int r, int a, int b) {
if (l >= b || r <= a) return 0;
if (a <= l && r <= b) return here.cnt;
int m = (l + r) / 2;
getch(here, l, r);
return cnt(*here.l, l, m, a, b) + cnt(*here.r, m, r, a, b);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int p2 = 1;
while (p2 < 16) p2 *= 2;
node root;
int c = 0;
int m; cin >> m;
while (m--) {
int d, x, y; cin >> d >> x >> y;
--x; --y;
x += c;
y += c;
if (d == 1) {
c = cnt(root, 0, p2, x, y + 1);
cout << c << '\n';
} else {
upd(root, 0, p2, x, y + 1);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |