FZU 1894 单一队列入门
FZU 1894 单调队列入门
Accept: 1296 Submit: 4081
世博会马上就要开幕了,福州大学组织了一次志愿者选拔活动。
参加志愿者选拔的同学们排队接受面试官们的面试。参加面试的同学们按照先来先面试并且先结束的原则接受面试官们的考查。
面试中每个人的人品是主要考查对象之一。(提高人品的方法有扶老奶奶过街,不闯红灯等)
作为主面试官的John想知道当前正在接受面试的同学队伍中人品值最高的是多少。于是他请你帮忙编写一个程序来计算。
输入数据第一行为一整数T,表示有T组输入数据。
每组数据第一行为”START”,表示面试开始
接下来的数据中有三种情况:
最后一行为”END”,表示所有的面试结束,面试的同学们可以依次离开了。
所有参加面试的同学总人数不超过1,000,000
对于每个询问Q,输出当前正在接受面试的队伍中人品最高的值,如果当前没有人正在接受面试则输出-1。
Problem 1894 志愿者选拔
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不推荐使用STLSource
福州大学第七届程序设计竞赛单调队列裸题,用一个双端队列维护一个递减的序列,然后扫一遍就行,由于数据规模超大,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; }