| | | | | | 背景 Background | | | | 话说小q的高中生活开始了~ | | | | |
| | | | | | 描述 Description | | | | 一天,小q冲到了食堂却发现饭卡没带(囧。。。),只好回去取,再回去的途中他还想知道他所排的队的情况,所以他让一个同学帮忙监视。(初始队列为0) 同学知道队列的进出情况。(具体请看样例) 针对小q的提问 同学得回答现在队伍里有多少人,还想知道队伍中最高的身高是多少。(想打架???。。。) | | | | |
| | | | | | 输入格式 Input Format | | | | 第一行 一个数 n 表示一共有多少个命令(包括进、出、询问) 接下来n行 第一个数为p 若p为1则表示小q询问队列里有多少人。 若p为2则表示最前面的已经买完饭了 出队了 若p为3则表示最后面的又来了1个人 后面还有一个数为身高(大于0小于maxint) 若p为4则表示询问在队中最高的身高为多少(如果没人请输出0)
| | | | |
| | | | | | 输出格式 Output Format | | | | 据每个p=1或4时的情况的回答(每行一个)
| | | | |
| | | | | | 时间限制 Time Limitation | | | | 各个测试点1s
| | | | |
| | | | | | 注释 Hint | | | | 40%的数据 保证n<= 1000 80%的数据 保证n<=100000 100%的数据 保证 n<= 800000 身高<=1000
| | | | |
|
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int inf = 910000 ;
int Q[inf];//单调队列值
int I[inf];//单调队列下标
int main()
{
//freopen("oo.txt","w",stdout);
int n;
while(scanf("%d",&n)==1)
{
int head=1,tail=0;
int l=0,r=0;//下标
while(n--)
{
int f;scanf("%d",&f);
if(f==1) //输出长度
{
int size=r-l;
printf("%d/n",size);
}
else if(f==2)//出队
{
l++;
while(head<=tail&&I[head]<=l) head++;
}
else if(f==3)//入队
{
int val;scanf("%d",&val);r++;
while(head<=tail&&Q[tail]<=val) tail--;
tail++;
Q[tail]=val,I[tail]=r;
}
else
{
int _max;
if(head<=tail) _max=Q[head];
else _max=0;
printf("%d/n",_max);
}
}
}
return 0;
}