Problem 1894 志愿者选拔
Accept: 1368 Submit: 4292
Time Limit: 1500 mSec Memory Limit : 32768 KB
Problem Description
Input
输入 | 含义 | |
1 | C NAME RP_VALUE | 名字为NAME的人品值为RP_VALUE的同学加入面试队伍。(名字长度不大于5,0 <= RP_VALUE <= 1,000,000,000) |
2 | G | 排在面试队伍最前面的同学面试结束离开考场。 |
3 | Q | 主面试官John想知道当前正在接受面试的队伍中人品最高的值是多少。 |
Output
Sample Input
2
START
C Tiny 1000000000
C Lina 0
Q
G
Q
END
START
Q
C ccQ 200
C cxw 100
Q
G
Q
C wzc 500
Q
END
Sample Output
1000000000
0
-1
200
100
500
#include<iostream>
#include<cstdio>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define N 10000
using namespace std;
struct node
{
int id;
int rp;
};
int main()
{
int t,d,id,front;
node n;
deque<node> q;//双端队列
char ch[100],c[100];
cin>>t;
while(t--)
{
front=id=1;
while(1)
{
scanf("%s",ch);
if(ch[0]=='C')
{
scanf("%s%d",c,&d);
n.id=id++;
n.rp=d;
while(!q.empty()&&q.back().rp<d)//比新来的人品小的都出队列
q.pop_back();
q.push_back(n);
}
if(ch[0]=='G')
{
front++;//走的人数
}
if(ch[0]=='Q')
{
if(front>=id)//走的比进的多
cout<<"-1"<<endl;
else
{
while(q.front().id<front)
q.pop_front();
cout<<q.front().rp<<endl;
}
}
if(ch[0]=='E')
{
while(!q.empty())//清空队列
q.pop_back();
break;
}
}
}
return 0;
}