HDU - 1540 Tunnel Warfare
set做法
#include<iostream>
#include<cstdio>
#include<set>
#include<stack>
using namespace std;
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
set<int> se={0,n+1};
stack<int> stk;
while(m--)
{
char op[2];scanf("%s",op);
if(*op=='D')
{
int x;scanf("%d",&x);
se.insert(x);stk.push(x);
}
if(*op=='Q')
{
int x;scanf("%d",&x);
int res = *se.upper_bound(x) - *(--se.upper_bound(x)) - 1;
if(se.count(x)) res=0;
printf("%d\n",res);
}
if(*op=='R'&&!stk.empty()) se.erase(stk.top()),stk.pop();
}
}
return 0;
}