Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

c++ set+stack 超简单实现......

Posted by xrb316 at 2013-05-14 20:42:14 on Problem 2892
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator