-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoj2892stl.cpp
40 lines (37 loc) · 898 Bytes
/
poj2892stl.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
#include <cstdio>
#include <set>
#include <stack>
using namespace std;
multiset<int> st;
stack<int> stk;
int main() {
int n, m;
scanf("%d %d\n", &n, &m);
char c;
int p;
while (m--) {
scanf("%c", &c);
if (c=='D') {
scanf("%d\n", &p);
st.insert(p);
stk.push(p);
} else if (c=='Q') {
scanf("%d\n", &p);
if (st.find(p)!=st.end()) {
printf("0\n");
continue;
}
multiset<int>::iterator it = st.upper_bound(p);
int max = it==st.end() ? n+1 : *it;
it = st.lower_bound(p);
int min = it==st.begin() ? 0 : *(--it);
printf("%d\n", max-min-1);
} else {
scanf("\n");
p = stk.top();
stk.pop();
st.erase(st.find(p));
}
}
return 0;
}