题目描述:
Sample Input
8
I 2
I -1
I 1
Q 3
L
D
R
Q 2
Sample Output
2
3
Hint
The following diagram shows the status of sequence after each instruction:
题意:
对一个数列进行操作,I:光标位置后面插入一个权值为x的数,D:删除光标前的那个数,L:光标左移一位,R:光标右移一位,Q:求1到光标前位置的最大的前缀和。
题解:
此题因为是求光标前的k个数的前缀和最大值,比较容易处理。
此题可以用两个栈来模拟,一个栈记录光标前的数,一个栈记录光标后的数,用数组sum[size]=sum[size-1]+m;记录前缀和,用mmax[size]=max(mmax[size-1],sum[size]);记录光标前最大值。以下是ac代码:
#include<iostream>
#include<cstdio>