
Accept: 1296 Submit: 4081
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
福州大学第七届程序设计竞赛
单调队列裸题,用一个双端队列维护一个递减的序列,然后扫一遍就行,由于数据规模超大,nlogn的方法会tle,单调队列也只能飘过。
代码:
/* ***********************************************
Author :_rabbit
Created Time :2014/5/12 22:14:46
File Name :20.cpp
************************************************ */
#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string>
#include <time.h>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
typedef long long ll;
int que[1001000],a[1001000];
int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
int T,head,end,front,tail;
char str[100],ss[223];
scanf("%d",&T);
while(T--){
front=tail=head=end=0;
scanf("%s",str);
while(~scanf("%s",str)&&str[0]!='E'){
if(str[0]=='C'){
scanf("%s",ss);
scanf("%d",&a[end++]);
while(front<tail&&a[que[tail-1]]<a[end-1])tail--;
que[tail++]=end-1;
}
else if(str[0]=='G')head++;
else {
if(head<end){
while(que[front]<head)front++;
printf("%d\n",a[que[front]]);
}
else puts("-1");
}
}
}
return 0;
}