码迷,mamicode.com
首页 > 其他好文 > 详细

XDOJ_1156_单调队列

时间:2016-10-30 00:10:38      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:color   space   编号   bre   cstring   namespace   scanf   deque   amp   

http://acm.xidian.edu.cn/problem.php?id=1156

 

递减的单调队列,保存人的编号和入队耐心-入队时间。

 

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;

struct st
{
    int num,t;
}s;
deque<st> q;
int n,x;

int main()
{
    while(~scanf("%d",&n))
    {
        while(!q.empty())   q.pop_back();
        int out = 1,cnt = 1;
        for(int i = 1;i <= n;i++)
        {
            scanf("%d",&x);
            switch(x)
            {
                case 1:
                    int tt;
                    scanf("%d",&tt);
                    s.t = tt-i;
                    s.num = cnt++;
                    while(!q.empty() && q.back().t <= s.t)    q.pop_back();
                    q.push_back(s);
                    break;
                case 2:
                    if(q.front().num == out++)  q.pop_front();
                    break;
                case 3:
                    printf("%d\n",q.front().t+i);
            }
        }
    }
    return 0;
}

 

XDOJ_1156_单调队列

标签:color   space   编号   bre   cstring   namespace   scanf   deque   amp   

原文地址:http://www.cnblogs.com/zhurb/p/6012073.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!