【NOIP2016提高A组模拟9.14】数列编辑器
2024-10-02 10:08:05
题目
分析
比赛上,没有注意到询问只询问光标前面,于是只打了个暴力。
因为询问只询问光标前面,首先,当光标向后每移动到一个位置,顺便将这个位置的前缀和,和最大前缀和求出来。
总之,模拟
#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]);
}
}
}
最新文章
- JavaScript 构造函数与原型链
- 在互联网公司参与拍卖是一种怎样的感觉?part 1
- iOS Assigning to &#39;id<;XXXDelegate>;&#39; from incompatible type &#39;BViewController *__strong&#39;
- ACM/ICPC 之 SPFA范例两道(POJ3268-POJ3259)
- 【转】打造属于自己的Android Studio神器
- poj 3635(bfs+优先队列)
- Js 对象三
- HDU-4272 LianLianKan
- APP安全环节缺失,手游运营商怎样应对APP破解困境
- 转:PO BO VO DTO POJO DAO概念及其作用
- 又一道软通动力7K月薪面试题——银行业务调度系统
- 解决ie6 闪动的问题
- oracle如何修改字段类型(oracle总体知识2)
- springmvc中使用response的out.print问题
- node.js抓取数据(fake小爬虫)
- DevExpress GridView 整理(转)
- RNQOJ 4 数列
- day40-socket编程
- vs断点未能绑定
- centOS7.0配置防火墙