#include<cstdio> #include<stack> #include<cstring> #include<algorithm> using namespace std; const int maxn=1000000; int Q1[maxn]; int Q2[maxn],r1,r2; int sum[maxn],dp[maxn]; int main(){ int n; while(scanf("%d",&n)!=EOF){ memset(Q1,0,sizeof(Q1)); memset(Q2,0,sizeof(Q2)); memset(sum,0,sizeof(sum)); memset(dp,0,sizeof(dp)); dp[0]=-(1<<29); r1=r2=0; char c; char p[10]; int num; while(n--){ scanf("%s",p); c=p[0]; if(c==‘I‘){ scanf("%d",&num); Q1[++r1]=num; sum[r1]=sum[r1-1]+num; dp[r1]=max(dp[r1-1],sum[r1]); } else if(c==‘D‘){ if(r1==0) continue; r1--; } else if(c==‘L‘){ if(r1==0) continue; Q2[++r2]=Q1[r1]; r1--; } else if(c==‘R‘){ if(r2==0) continue; num=Q2[r2--]; Q1[++r1]=num; sum[r1]=sum[r1-1]+num; dp[r1]=max(dp[r1-1],sum[r1]); } else{ scanf("%d",&num); printf("%d\n",dp[num]); } } } return 0; }
原文地址:https://www.cnblogs.com/lmjer/p/8974524.html
时间: 2024-11-15 06:25:38