#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 1e9+10;
struct node {
int cnt;
int l, r;
} seg[100'000'000];
int rt;
int new_node()
{
static int nxt = 1;
return nxt++;
}
void up(int i)
{
assert(seg[i].l);
assert(seg[i].r);
seg[i].cnt = seg[seg[i].l].cnt + seg[seg[i].r].cnt;
}
void seg_set(int l, int r, int i, int b, int e)
{
if (l <= b && e <= r) {
seg[i].cnt = e-b;
return;
}
if (r <= b || e <= l || seg[i].cnt == e-b)
return;
if (!seg[i].l)
seg[i].l = new_node();
if (!seg[i].r)
seg[i].r = new_node();
seg_set(l, r, seg[i].l, b, (b+e)/2);
seg_set(l, r, seg[i].r, (b+e)/2, e);
up(i);
}
int seg_get(int l, int r, int i, int b, int e)
{
if (l <= b && e <= r)
return seg[i].cnt;
if (r <= b || e <= l || seg[i].cnt == 0)
return 0;
if (seg[i].cnt == e-b)
return min(e, r) - max(b, l);
assert(seg[i].l);
assert(seg[i].r);
return seg_get(l,r,seg[i].l,b,(b+e)/2)
+ seg_get(l,r,seg[i].r,(b+e)/2,e);
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
rt = new_node();
int C = 0;
int q;
cin >> q;
while (q--) {
int d, l, r;
cin >> d >> l >> r;
l += C-1; r += C;
if (d == 1) {
int x = seg_get(l, r, rt, 0, N);
C = x;
cout << x << '\n';
} else {
seg_set(l, r, rt, 0, N);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
340 KB |
Output is correct |
8 |
Correct |
18 ms |
528 KB |
Output is correct |
9 |
Correct |
38 ms |
624 KB |
Output is correct |
10 |
Correct |
36 ms |
676 KB |
Output is correct |
11 |
Correct |
34 ms |
624 KB |
Output is correct |
12 |
Correct |
36 ms |
604 KB |
Output is correct |
13 |
Correct |
43 ms |
696 KB |
Output is correct |
14 |
Correct |
44 ms |
2820 KB |
Output is correct |
15 |
Correct |
35 ms |
2856 KB |
Output is correct |
16 |
Correct |
41 ms |
2908 KB |
Output is correct |
17 |
Correct |
49 ms |
2812 KB |
Output is correct |
18 |
Correct |
46 ms |
2804 KB |
Output is correct |
19 |
Correct |
36 ms |
3004 KB |
Output is correct |
20 |
Correct |
35 ms |
2892 KB |
Output is correct |