AcWing 128. 编辑器
原题链接
简单
作者:
AWA_QWQ
,
2019-04-10 10:05:25
,
所有人可见
,
阅读 1768
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+100;
int t,x,sum[N],f[N],now;
stack<int> a,b,c;
int main()
{
while(scanf("%d\n",&t)!=EOF)
{
a=c;
b=c;
f[0]=-1e7;
sum[0]=0;
for(int i=1;i<=t;i++)
{
char ch=getchar();
if (ch=='I')
{
scanf(" %d",&x);
a.push(x);
sum[a.size()]=sum[a.size()-1]+a.top();
f[a.size()]=max(f[a.size()-1],sum[a.size()]);
}
if (ch=='D')
if (!a.empty())
a.pop();
if (ch=='L')
if(!a.empty())
b.push(a.top()),a.pop();
if (ch=='R')
{
if (!b.empty())
{
a.push(b.top());
b.pop();
sum[a.size()]=sum[a.size()-1]+a.top();
f[a.size()]=max(f[a.size()-1],sum[a.size()]);
}
}
if (ch=='Q')
{
scanf(" %d",&x);
printf("%d\n",f[x]);
}
getchar();
}
}
return 0;
}
看了题解过来,抄袭就不对了吧大哥......
qp如果这是在洛谷出现的话,你早就棕了!!!
抄袭可耻......
这踩是咋回事.....
有我一份力
一千浏览,60个踩……