#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
//#define int long long
const int N = 1e7 + 69;
int st[4 * N], q, c;
void push(int v, int tl, int tr) {
int mid = (tl + tr) / 2;
int s = tr - tl + 1;
if (st[v] == s) {
st[v * 2] = mid - tl + 1;
st[v * 2 + 1] = tr - mid;
}
}
void upd(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return;
else if (tl >= l && tr <= r)
st[v] = (tr - tl + 1);
else {
int mid = (tl + tr) / 2;
push(v, tl, tr);
upd(v * 2, tl, mid, l, r);
upd(v * 2 + 1, mid + 1, tr, l, r);
st[v] = st[v * 2] + st[v * 2 + 1];
}
}
int get(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return 0;
else if (tl >= l && tr <= r)
return st[v];
else {
int mid = (tl + tr) / 2;
push(v, tl, tr);
return get(v * 2, tl, mid, l, r) + get(v * 2 + 1, mid + 1, tr, l, r);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> q;
while (q--) {
int t, l, r;
cin >> t >> l >> r;
l += c, r += c;
if (t == 2) {
upd(1, 1, N, l, r);
}
else {
c = get(1, 1, N, l, r);
cout << c << '\n';
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
8 ms |
11612 KB |
Output is correct |
5 |
Correct |
9 ms |
16476 KB |
Output is correct |
6 |
Correct |
10 ms |
16856 KB |
Output is correct |
7 |
Correct |
9 ms |
16732 KB |
Output is correct |
8 |
Correct |
55 ms |
59480 KB |
Output is correct |
9 |
Correct |
98 ms |
71748 KB |
Output is correct |
10 |
Correct |
105 ms |
99412 KB |
Output is correct |
11 |
Correct |
117 ms |
122092 KB |
Output is correct |
12 |
Correct |
135 ms |
133200 KB |
Output is correct |
13 |
Incorrect |
45 ms |
127316 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |