#include <bits/stdc++.h>
using namespace std;
const int maxn = (int) 1e6 + 7;
int seg[4 * maxn + 7];
int lazy[4 * maxn + 7];
void down(int id, int l, int r) {
if (lazy[id] && l < r) {
int &v = lazy[id];
int g = (l + r) >> 1;
seg[id << 1] = g - l + 1;
seg[id << 1 | 1] = r - g;
lazy[id << 1] += v;
lazy[id << 1 | 1] += v;
v = 0;
return;
}
}
void update(int id, int l, int r, int u, int v) {
if (l > v || u > r) return;
if (u <= l && r <= v) {
seg[id] = r - l + 1;
lazy[id] = 1;
return;
}
down(id, l, r);
int g = (l + r) >> 1;
update(id << 1, l, g, u, v);
update(id << 1 | 1, g + 1, r, u, v);
seg[id] = seg[id << 1] + seg[id << 1 | 1];
}
int get(int id, int l, int r, int u, int v) {
if (l > v || u > r) return 0;
if (u <= l && r <= v) return seg[id];
down(id, l, r);
int g = (l + r) >> 1;
return get(id << 1, l, g, u, v) + get(id << 1 | 1, g + 1, r, u, v);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n;
cin >> n;
int preAns = 0;
while (n--) {
int type, l, r;
cin >> type >> l >> r;
l += preAns;
r += preAns;
if (type == 2) {
update(1, 1, maxn, l, r);
} else {
cout << (preAns = get(1, 1, maxn, l, r)) << "\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |