zoukankan      html  css  js  c++  java
  • hdoj4699 Editor

    被题目坑爹好狠  是1到j(1<=j<=k)的最大和。。。还以为是k之前的最大字段和。。。

    操作不用我说了把,两个对顶堆分别维护,单次操作复杂度O(1)

    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int N=1e6+5,inf=2147483647;
    int s1[N],s2[N],m1[N],m2[N];
    int main(){
    //    freopen("a.txt","r",stdin);
        int Q;
        m2[0]=-inf;
        while(scanf("%d",&Q)!=EOF){
            int t1=0,t2=0;
            for(register int i=1;i<=Q;++i){
                char opt;
                while((opt=getchar())&&(opt<'A'||opt>'Z'));
                if(opt=='I'){
                    int x;
                    scanf("%d",&x);
                    s1[++t1]=x;
                    m1[t1]=m1[t1-1]+x;
                    m2[t1]=max(m2[t1-1],m1[t1]);
                }
                else if(opt=='D'&&t1!=0){
                    --t1;
                }
                else if(opt=='L'&&t1!=0){
                    s2[++t2]=s1[t1];--t1;
                }
                else if(opt=='R'&&t2!=0){
                    s1[++t1]=s2[t2];
                    m1[t1]=m1[t1-1]+s2[t2];
                    m2[t1]=max(m2[t1-1],m1[t1]);
                    --t2;
                }
                else if(opt=='Q'){
                    int x;
                    scanf("%d",&x);
                    printf("%d
    ",m2[x]);
                }
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    TCP/IP四层模型
    Java中equals和==的区别
    最全前端资源汇集
    (转)php面向对象学习笔记
    学习内容
    Gulp入门教程
    seajs的CMD模式的优势以及使用
    正则
    Grunt
    Javascript 异步加载详解
  • 原文地址:https://www.cnblogs.com/Dream-Runner/p/10152113.html
Copyright © 2011-2022 走看看