zoukankan      html  css  js  c++  java
  • Jzoj4778 数列编辑器

    我们发现前四个操作可以用双向链表维护,而最后一个操作有一个限制就是1<=k<=n,所以可以用一个数组存在光标前面的数,每次维护一下前缀和就好

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #define N 1000010
    using namespace std;
    int l[N],r[N],s[N]; char c[5];
    int w[N],f[N]={-1<<29},n=0,m,t,cnt=0;
    int main(){
    	freopen("editor.in","r",stdin);
    	freopen("editor.out","w",stdout);
    	scanf("%d",&m);
    	for(int x;m--;){
    		scanf("%s",c);
    		if(*c=='I'){
    			scanf("%d",&x);
    			++n; ++cnt;
    			l[cnt]=t; r[cnt]=r[t];
    			l[r[t]]=cnt; r[t]=cnt;
    			w[n]=w[n-1]+x; t=cnt;
    			s[t]=x; f[n]=max(f[n-1],w[n]);
    		} else if(*c=='D'){
    			r[l[t]]=r[t];
    			l[r[t]]=l[t];
    			t=l[t];  --n;
    		} else if(*c=='R'){
    			if(r[t]){
    				t=r[t];
    				++n; w[n]=w[n-1]+s[t];
    				f[n]=max(f[n-1],w[n]);
    			}
    		} else if(*c=='L'){
    			if(n){ --n; t=l[t]; }
    		} else { 
    			scanf("%d",&x); 
    			printf("%d
    ",f[x]);
    		}
    	}
    }

  • 相关阅读:
    canvas制作倒计时炫丽效果
    MySQL存储过程
    SpringMVC入门
    JAVA面试/笔试经典题
    JAVA内存存储分配粗略讲解
    数据结构算法总结
    稳定排序
    Java集合框架
    Java笔试题及答案
    面向接口
  • 原文地址:https://www.cnblogs.com/Extended-Ash/p/7774340.html
Copyright © 2011-2022 走看看