单调队列 fzu1894 志愿者选拔

传送门:点击打开链接

题意:3种操作:队列中加入一个人;队首出队;求队中权值最大是多少

思路:运用单调队列来维护。其实单调队列中其实id也是有序的,所以队列出队只要看单调队列的第一个是否等于队首那个就行了。

#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define fuck(x) cout<<"["<<x<<"]"
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout)
using namespace std;
typedef long long LL;

const int MX = 1e6 + 5;
const int INF = 0x3f3f3f3f;

char w[100];
int A[MX];
int Q[MX], cur, rear;

int main() {
    int T; //FIN;
    scanf("%d", &T);
    while(T--) {
        int n = 0, L = 1;
        cur = rear = 0;
        while(scanf("%s", w), w[0] != 'E') {
            if(w[0] == 'S') continue;
            if(w[0] == 'C') {
                scanf("%s%d", w, &A[++n]);
                while(cur < rear && A[Q[rear - 1]] < A[n]) rear--;
                Q[rear++] = n;
            } else if(w[0] == 'G') {
                if(cur < rear && Q[cur] == L) cur++;
                L++;
            } else {
                if(cur == rear) printf("-1\n");
                else printf("%d\n", A[Q[cur]]);
            }
        }

    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值