| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
c++ set+stack 超简单实现......#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<set>
#include<stack>
using namespace std;
int n,m;
set<int>s;
stack<int>sta;
int main()
{
scanf("%d%d\n",&n,&m);
s.insert(0); s.insert(n+1);
for(int i=0;i<m;i++)
{
char c; int x;
scanf("%c",&c);
if(c=='D')
{
scanf("%d\n",&x);
s.insert(x);
sta.push(x);
}
if(c=='R')
{
scanf("\n");
x=sta.top();
sta.pop();
s.erase(x);
}
if(c=='Q')
{
scanf("%d\n",&x);
int l,r;
r=*s.lower_bound(x);
l=*(--s.lower_bound(x));
if(r==x) printf("0\n");
else printf("%d\n",r-l-1);
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator