您的位置:首页 > 其它

fzu 1894 单调队列

2014-07-17 14:29 148 查看
http://acm.fzu.edu.cn/problem.php?pid=1894

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>

typedef struct Node
{
int num;
char name[10];
int data;
}queue;
queue f[1000010];

int main()
{
int n,m,i,j,tail,head;
scanf("%d",&n);
queue tmp;

while(n--)
{
char cur[10];
int Num=0,count=0;
head=0,tail=-1;
while(scanf("%s",cur)!=EOF)
{
if(cur[0]=='C')
{
scanf("%s%d",tmp.name,&tmp.data);
tmp.num=++Num;

while(head<=tail && f[tail].data<tmp.data)
{
tail--;
}

f[++tail]=tmp;
}
if(cur[0]=='S')continue;
if(cur[0]=='E')break;
if(cur[0]=='Q')
{
while(tail>=head && f[head].num<=count)
{
head++;
}
if(head>tail)printf("-1\n");
else
printf("%d\n",f[head].data);
}
if(cur[0]=='G')
{
count++;
}
}
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: