#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const int M = 1e9;
const ll linf = 1e18;
int st[100 * N], lc[100 * N], rc[100 * N], lzy[100 * N], tsz, root;
void Propagate(int c, int l, int r) {
if (lzy[c] == 0) return;
if (l < r) {
if (!lc[c]) lc[c] = ++tsz;
lzy[lc[c]] = lzy[c];
if (!rc[c]) rc[c] = ++tsz;
lzy[rc[c]] = lzy[c];
}
st[c] = r - l + 1;
lzy[c] = 0;
}
void Set(int &c, int l, int r, int ql, int qr) {
if (!c) c = ++tsz;
Propagate(c, l, r);
if (r < ql || qr < l) return;
if (ql <= l && r <= qr) {
lzy[c] = 1;
Propagate(c, l, r);
return;
}
int mid = l + r >> 1;
Set(lc[c], l, mid, ql, qr);
Set(rc[c], mid + 1, r, ql, qr);
st[c] = st[lc[c]] + st[rc[c]];
}
int Get(int &c, int l, int r, int ql, int qr) {
if (!c) c = ++tsz;
Propagate(c, l, r);
if (r < ql || qr < l) return 0;
if (ql <= l && r <= qr) return st[c];
int mid = l + r >> 1;
return Get(lc[c], l, mid, ql, qr) + Get(rc[c], mid + 1, r, ql, qr);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int q; cin >> q;
int C = 0;
while (q--) {
int t, x, y;
cin >> t >> x >> y;
x += C; y += C;
if (t == 1) {
C = Get(root, 1, M, x, y);
cout << C << en;
}
else Set(root, 1, M, x, y);
}
return 0;
}
Compilation message
apple.cpp: In function 'void Set(int&, int, int, int, int)':
apple.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | int mid = l + r >> 1;
| ~~^~~
apple.cpp: In function 'int Get(int&, int, int, int, int)':
apple.cpp:43:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
13 ms |
3084 KB |
Output is correct |
5 |
Correct |
20 ms |
3676 KB |
Output is correct |
6 |
Correct |
16 ms |
3580 KB |
Output is correct |
7 |
Correct |
19 ms |
3624 KB |
Output is correct |
8 |
Correct |
125 ms |
25940 KB |
Output is correct |
9 |
Correct |
268 ms |
44060 KB |
Output is correct |
10 |
Correct |
272 ms |
49448 KB |
Output is correct |
11 |
Correct |
270 ms |
53596 KB |
Output is correct |
12 |
Correct |
280 ms |
55360 KB |
Output is correct |
13 |
Correct |
255 ms |
68896 KB |
Output is correct |
14 |
Correct |
265 ms |
69480 KB |
Output is correct |
15 |
Correct |
410 ms |
127320 KB |
Output is correct |
16 |
Correct |
421 ms |
129684 KB |
Output is correct |
17 |
Correct |
266 ms |
74120 KB |
Output is correct |
18 |
Correct |
283 ms |
74152 KB |
Output is correct |
19 |
Correct |
410 ms |
132712 KB |
Output is correct |
20 |
Correct |
402 ms |
132800 KB |
Output is correct |