Jzoj4778 数列编辑器
生活随笔
收集整理的這篇文章主要介紹了
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\n",f[x]);}} }轉載于:https://www.cnblogs.com/Extended-Ash/p/9477281.html
總結
以上是生活随笔為你收集整理的Jzoj4778 数列编辑器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ssh报错解决 ECDSA host k
- 下一篇: linux下scrt依赖包libssl1