zoukankan      html  css  js  c++  java
  • fzu 1894 志愿者选拔 (单调队列)

    简单单调队列。

    code:

    #include<cstdio>
    int data[1000001] ;
    int queue[1000001] ;
    int num[1000001] ;
    int h, r, n ;
    void insert(){
        if(r==h-1||data[n]<queue[r]){
            r ++ ;
            queue[r] = data[n] ;
            num[r] = n ;
        }
        else{
            while(r>=h&&data[n]>=queue[r])
                r -- ;
            queue[++r] = data[n] ;
            num[r] = n ;
        }
    }
    void getMax(){
        if(h>r) printf("-1\n") ;
        else    printf("%d\n", queue[h]) ;
    }
    int main(){
        char temp[6] ;
        int t, l ;
        scanf("%d", &t) ;
        while(t--){
            h = n = l = 0 ;
            r = -1 ;
            queue[0] = 0 ;
            scanf("%s", temp) ;
            while(true){
                scanf("%s", temp) ;
                if(temp[0]=='C'){
                    scanf("%s", temp) ;
                    scanf("%d", &data[n]) ;
                    insert() ;
                    n ++ ;
                }
                else if(temp[0]=='Q'){
                    while(r>=h&&num[h]<l)
                        h ++ ;
                    getMax() ;
                }
                else if(temp[0]=='G')
                    l ++ ;
                else break ;
            }
        }
        return 0 ;

    }

  • 相关阅读:
    ElasticSearch搜索引擎安装配置拼音插件pinyin
    ElasticSearch搜索引擎安装配置中文分词器IK插件
    Linux系统中ElasticSearch搜索引擎安装配置Head插件
    阿里云服务器Linux系统安装配置ElasticSearch搜索引擎
    盒子模型
    div与span的区别
    .与localhost与 .sqlexpress的区别
    C#-多态
    C#-里氏转换
    C#-继承
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2344682.html
Copyright © 2011-2022 走看看