Problem 1894 志愿者选拔
Accept: 1937 Submit: 5969
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 <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std;
#define LL long long
const int INF=0x3f3f3f3f;
const int MAXN=1000010;
char s1[10],s2[10];
int q[MAXN][2];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",s1);
int head=0,rear=0;
int x=0,cnt=0,a;
while(1)
{
scanf("%s",s1);
if(!strcmp(s1,"END")) break;
if(!strcmp(s1,"C"))
{
scanf("%s %d",s2,&a);
while(head<rear&&q[rear-1][0]<a) rear--;
q[rear][0]=a;
q[rear++][1]=++cnt;
}
else if(!strcmp(s1,"Q"))
{
if(head==rear) printf("-1\n");
else printf("%d\n",q[head][0]);
}
else
{
if(head==rear) continue;
x++;
if(q[head][1]<=x) head++;
}
}
}
return 0;
}