Accept: 1299 Submit: 4084
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
2STARTC Tiny 1000000000C Lina 0QGQENDSTARTQC ccQ 200C cxw 100QGQC wzc 500QEND
Sample Output
10000000000-1200100500
Hint
数据较大建议使用scanf,printf 不推荐使用STL
Source
福州大学第七届程序设计竞赛
思路: 单调队列裸题
详见代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=1000000+100;
int head,tail;
char s[15],name[15];
struct node
{
int val,index;
}que[MAXN];
int main()
{
//freopen("text.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
int cnt=0,out=0;
head=tail=0;
while(~scanf("%s",s) && s[0]!='E')
{
if(s[0]=='C')
{
int x; cnt++;
scanf("%s%d",name,&x);
while(head<tail && que[tail-1].val<=x) tail--;
que[tail].val=x; que[tail++].index=cnt;
}
if(s[0]=='G')
{
out++;
if(que[head].index==out)
head++;
}
if(s[0]=='Q')
{
if(head>=tail)
printf("-1\n");
else
printf("%d\n",que[head].val);
}
}
}
return 0;
}