#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Node {
ll tl, tr, sum, lazy;
Node *left = nullptr, *right = nullptr;
Node(ll l, ll r) : tl(l), tr(r), sum(0), lazy(0) {}
};
void push(Node *v) {
if (v->tl == v->tr) return;
ll tm = (v->tl + v->tr) / 2;
if (!v->left) v->left = new Node(v->tl, tm);
if (!v->right) v->right = new Node(tm+1, v->tr);
if (v->lazy == 1) {
v->left->sum = (tm - v->tl + 1);
v->right->sum = (v->tr - tm);
v->left->lazy = 1;
v->right->lazy = 1;
v->lazy = 0;
}
}
ll query(Node *v, ll l, ll r) {
push(v);
if (l > v->tr || r < v->tl)
return 0;
if (l <= v->tl && v->tr <= r)
return v->sum;
return (v->left ? query(v->left, l, r) : 0) + (v->right ? query(v->right, l, r) : 0);
}
void update(Node *v, ll l, ll r) {
push(v);
if (l > v->tr || r < v->tl)
return;
if (l <= v->tl && v->tr <= r) {
v->lazy = 1;
v->sum = (v->tr - v->tl + 1);
return;
}
update(v->left, l, r);
update(v->right, l, r);
v->sum = (v->left ? v->left->sum : 0) + (v->right ? v->right->sum : 0);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q;
cin >> q;
Node *root = new Node(1, 1e9);
ll ans = 0;
while (q--) {
ll op, l, r;
cin >> op >> l >> r;
l += ans; r += ans;
if (op == 1) {
ans = query(root, l, r);
cout << ans << endl;
} else {
update(root, l, r);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
20 ms |
11348 KB |
Output is correct |
5 |
Correct |
25 ms |
13800 KB |
Output is correct |
6 |
Correct |
26 ms |
13176 KB |
Output is correct |
7 |
Correct |
25 ms |
13648 KB |
Output is correct |
8 |
Correct |
181 ms |
102616 KB |
Output is correct |
9 |
Correct |
381 ms |
174368 KB |
Output is correct |
10 |
Correct |
488 ms |
196036 KB |
Output is correct |
11 |
Correct |
427 ms |
212608 KB |
Output is correct |
12 |
Correct |
424 ms |
219980 KB |
Output is correct |
13 |
Runtime error |
389 ms |
262144 KB |
Execution killed with signal 9 |
14 |
Halted |
0 ms |
0 KB |
- |