分析:不需要线段树,set可过,STL大法好
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <stack>
using namespace std;
const int N=5e4+;
set<int>s;
bool d[N];
stack<int>p;
char o[];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(d,,sizeof(d));
while(!p.empty())p.pop();
s.clear();
while(m--)
{
int u;
scanf("%s",o);
if(o[]=='R')
{
u=p.top();
p.pop();
d[u]=;
if(s.find(u)!=s.end())s.erase(u);
}
else if(o[]=='D')
{
scanf("%d",&u);
d[u]=;
if(s.find(u)==s.end())s.insert(u);
p.push(u);
}
else
{
scanf("%d",&u);
if(d[u])printf("0\n");
else
{
set<int>::iterator it=s.lower_bound(u);
int ans=n;
if(it!=s.end())ans=(*it)-;
ans=ans-u;
int x;
if(it==s.begin())x=;
else
{
it--;
x=(*it);
}
ans+=u-x;
printf("%d\n",ans);
}
}
}
}
}