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]);
    		}
    	}
    }

  • 相关阅读:
    20180827 360笔试客观题
    20180821 hikvision笔试
    20180820 美团一面
    20180811 网易
    20180811 多益网络
    20180810 多益网络模拟笔试
    hbase --知识点总结
    flume知识点总结
    oracle --hint总结
    查看oracle的执行计划
  • 原文地址:https://www.cnblogs.com/Extended-Ash/p/9477281.html
Copyright © 2011-2022 走看看