题目

分析

比赛上,没有注意到询问只询问光标前面,于是只打了个暴力。

因为询问只询问光标前面,首先,当光标向后每移动到一个位置,顺便将这个位置的前缀和,和最大前缀和求出来。

总之,模拟

#include <cmath>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxlongint=2147483647;
const int N=1000005;
const int mo=1000000007;
int next[N],last[N],a[N],n,tot,num,sum[N],tt,mx[N],pos[N];
int main()
{
scanf("%d",&n);
for(int i=0;i<N;i++) mx[i]=-maxlongint;
next[0]=n+1;
last[n+1]=0;
for(int i=1;i<=n;i++)
{
char c=getchar();
while(c!='I' && c!='D' && c!='L' && c!='R' && c!='Q') c=getchar();
int x;
if(c=='I')
{
scanf("%d",&x);
num++;
tt++;
last[next[tot]]=tt;
next[tt]=next[tot];
last[tt]=tot;
next[tot]=tt;
a[tt]=x;
sum[tt]=sum[tot]+a[tt];
pos[tt]=pos[tot]+1;
mx[pos[tt]]=max(sum[tt],mx[pos[tot]]);
tot=tt;
}
else
if(c=='D')
{
num--;
next[last[tot]]=next[tot];
last[next[tot]]=last[tot];
a[tot]=sum[tot]=0;
tot=last[tot];
}
else
if(c=='L')
{
tot=last[tot];
}
else
if(c=='R')
{
if(pos[tot]<num) tot=next[tot];
else continue;
sum[tot]=sum[last[tot]]+a[tot];
pos[tot]=pos[last[tot]]+1;
mx[pos[tot]]=max(sum[tot],mx[pos[last[tot]]]);
}
else
if(c=='Q')
{
scanf("%d",&x);
printf("%d\n",mx[x]);
}
}
}

最新文章

  1. JavaScript 构造函数与原型链
  2. 在互联网公司参与拍卖是一种怎样的感觉?part 1
  3. iOS Assigning to &#39;id&lt;XXXDelegate&gt;&#39; from incompatible type &#39;BViewController *__strong&#39;
  4. ACM/ICPC 之 SPFA范例两道(POJ3268-POJ3259)
  5. 【转】打造属于自己的Android Studio神器
  6. poj 3635(bfs+优先队列)
  7. Js 对象三
  8. HDU-4272 LianLianKan
  9. APP安全环节缺失,手游运营商怎样应对APP破解困境
  10. 转:PO BO VO DTO POJO DAO概念及其作用
  11. 又一道软通动力7K月薪面试题——银行业务调度系统
  12. 解决ie6 闪动的问题
  13. oracle如何修改字段类型(oracle总体知识2)
  14. springmvc中使用response的out.print问题
  15. node.js抓取数据(fake小爬虫)
  16. DevExpress GridView 整理(转)
  17. RNQOJ 4 数列
  18. day40-socket编程
  19. vs断点未能绑定
  20. centOS7.0配置防火墙

热门文章

  1. Sqlserver实现故障转移 — 域控(1)
  2. CTF—攻防练习之HTTP—SQl注入(get)
  3. /etc/sysctl.conf 控制内核相关配置文件
  4. ubuntu修改时间为北京时间
  5. Django框架中使用Echart进行统计的SQL语句
  6. AKKA学习(二) 未完
  7. NEO4J亿级数据导入导出以及数据更新
  8. 剑指offer 数字翻译成字符串
  9. EditPlus配置Java编译器
  10. Git 设置 用户名 和 邮箱