hdu 4699 Editor 模拟
多校10,1004 比赛的时候一直想构造个伸展树,结果写挫了。赛后发现其实就两个栈,顿时感觉被虐成渣了
/* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <stack> using namespace std; stack<int> a,b; int sum[1000005]; int Max[1000005]; int now; int main() { int Q; while(~scanf("%d",&Q)) { while(!a.empty())a.pop(); while(!b.empty())b.pop(); int i,t; char c; sum[0]=0; Max[0]=-1E9; now=0; for(i=0;i<Q;i++) { getchar(); c=getchar(); switch(c) { case 'I': scanf("%d",&t); a.push(t); now++; sum[now]=sum[now-1]+t; Max[now]=max(Max[now-1],sum[now]); break; case 'D': if(!a.empty()) { a.pop(); now--; } break; case 'L': if(!a.empty()) { b.push(a.top());a.pop(); now--; } break; case 'R': if(!b.empty()) { a.push(b.top());b.pop(); now++; sum[now]=sum[now-1]+a.top(); Max[now]=max(Max[now-1],sum[now]); } break; case 'Q': scanf("%d",&t); printf("%d\n",Max[t]); break; } } } }
最后更新:2017-04-03 16:49:00