P2201 数列编辑器 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162#include<iostream>#include<algorithm>using namespace std;#define re registerconst int MAXn = 1e6;template <class T>inline void read(T &a) { register char c;while (c = getchar(), (c < '0' || c > '9') && c != '-');register bool f = c == '-';register T x = f ? 0 : c - '0';while (c = getchar(), c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + (c ^ 48);}a = f ? -x : x;}struct Ele { int val, sum, maxsum; Ele(){} Ele(int val_):val(val_){}};struct Stack { int top; Ele stk[MAXn + 10]; inline void Push(int x) { stk[++top] = Ele(x); } inline int Pop() { return stk[top--].val; }}fro, beh;int n;int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; char opt; for (re int i = 1, x; i <= n; ++i) { cin >> opt; switch (opt) { case 'I': cin >> x; fro.Push(x); fro.stk[fro.top].sum = fro.stk[fro.top - 1].sum + fro.stk[fro.top].val; fro.stk[fro.top].maxsum = (fro.top == 1) ? fro.stk[fro.top].sum : max(fro.stk[fro.top - 1].maxsum, fro.stk[fro.top].sum); break; case 'D': fro.Pop(); break; case 'L': beh.Push(fro.Pop()); break; case 'R': fro.Push(beh.Pop()); fro.stk[fro.top].sum = fro.stk[fro.top - 1].sum + fro.stk[fro.top].val; fro.stk[fro.top].maxsum = (fro.top == 1) ? fro.stk[fro.top].sum : max(fro.stk[fro.top - 1].maxsum, fro.stk[fro.top].sum); break; case 'Q': cin >> x; cout << fro.stk[x].maxsum << '\n'; } }}