-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPBDS.cpp
91 lines (61 loc) · 1.78 KB
/
PBDS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef pair<long long, long long> pii;
template <typename T>
using ordered_set = tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>;
unordered_map<long long, int> id;
ordered_set<pii> segments;
set<long long> points;
int main()
{
int test, cs = 0;
scanf("%d", &test);
while(test--)
{
long long n, q, x, n1, n2, cur;
scanf("%lld %lld", &n, &q);
segments.insert(make_pair(n, ++id[n]));
points.insert(0);
points.insert(n);
printf("Case %d:\n", ++cs);
while(q--)
{
char ss[2];
scanf("%s", ss);
if(ss[0]=='C')
{
scanf("%lld", &x);
if(x>n) continue;
auto it = points.lower_bound(x);
long long up = *it;
it--;
long long down = * it;
if(up==x||down==x) continue;
points.insert(x);
long long cur = up - down;
int xxx = id[cur];
segments.erase(make_pair(cur,xxx));
id[cur]--;
if(up-x>0)
{
segments.insert(make_pair(up-x,++id[up-x]));
}
if(x-down>0)
segments.insert(make_pair(x-down,++id[x-down]));
}
else
{
int k;
scanf("%d", &k);
pii temp = *segments.find_by_order(k-1);
printf("%lld\n",temp.first);
}
}
segments.clear();
points.clear();
id.clear();
}
}