浅谈栈:https://www.cnblogs.com/AKMer/p/10278222.html

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4699

用对顶栈模拟即可。\(stk1\)表示光标之前的数列,\(stk2\)表示光标之后的数列。然后维护一下前缀和以及前缀和的最大值即可。

对于插入,直接往\(stk1\)里扔这个数字然后更新\(sum\)和\(mx\)。

对于删除,直接弹栈\(stk1\)。

对于左移,弹栈\(stk1\)并把弹出来的元素压进\(stk2\)。

对于右移,弹栈\(stk2\)并把弹出来的元素压进\(stk1\)。

对于查询,输出\(mx_k\)即可。

时间复杂度:\(O(n)\)

空间复杂度:\(O(n)\)

代码如下:

#include <cstdio>
#include <algorithm>
using namespace std; const int maxn=1e6+5; char opt[5];
int n,top1,top2;
int stk1[maxn],stk2[maxn],mx[maxn],sum[maxn]; int read() {
int x=0,f=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
} void insert(int x) {
stk1[++top1]=x;
sum[top1]=sum[top1-1]+x;
mx[top1]=max(mx[top1-1],sum[top1]);
} int main() {
mx[0]=-2e9;
while(~scanf("%d",&n)) {
top1=top2=0;
for(int i=1;i<=n;i++) {
scanf("%s",opt+1);
if(opt[1]=='I') {
int x=read();
insert(x);
}
if(opt[1]=='D'&&top1)top1--;
if(opt[1]=='L'&&top1)
stk2[++top2]=stk1[top1],top1--;
if(opt[1]=='R'&&top2)
insert(stk2[top2]),top2--;
if(opt[1]=='Q') {
int k=read();
printf("%d\n",mx[k]);
}
}
}
return 0;
}

HDU4699:Editor的更多相关文章

  1. 无废话ExtJs 入门教程十四[文本编辑器:Editor]

    无废话ExtJs 入门教程十四[文本编辑器:Editor] extjs技术交流,欢迎加群(201926085) ExtJs自带的编辑器没有图片上传的功能,大部分时候能够满足我们的需要. 但有时候这个功 ...

  2. CodeMirror动态修改代码(关键: editor.getDoc().setValue(data); editor.refresh();)

    在使用codemirror时,其原理是根据form中的textarea标签,自动加载其内容,获得代码行的显示.(具体使用方式参见 codemirror官网使用手册 http://codemirror. ...

  3. Unity扩展编辑器--类型1:Editor Windows

    Extending the Editor Unity允许你使用自己定制的inspectors和Editor Windows扩展编辑器,并且你可以使用定制的Property Drawers定义属性集在i ...

  4. Unity3D学习笔记(二十八):Editor

    Editor: 对编辑器进行一些拓展开发 关于继承Mono类的扩展开发   特性: [特性]:声明性的标签(类,方法,结构体,变量) 特性只对字段声明有效,后面必须接字段:多个特性,可以修饰一个字段 ...

  5. 【题解】Editor [HDU4699]

    [题解]Editor [HDU4699] 传送: \(Editor\) \([HDU4699]\) [题目描述] 有一个维护整数序列的强大编辑器,初始状态为空,下面提供五种不同的操作,给出的总操作次数 ...

  6. 每天一个linux命令(50):crontab命令

    前一天学习了 at 命令是针对仅运行一次的任务,循环运行的例行性计划任务,linux系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个 ...

  7. 编写 Unity Editor 插件

    Editor Style Viewer 在开发过程中,我喜欢编写一些辅助的Editor插件,方便在游戏开发过程进行调试. 下面是摘自Asset Store的一个查看Unity 默认GUI样式的小工具 ...

  8. 实现BPEL4WS演示:教程

    http://www.ibm.com/developerworks/cn/education/webservices/ws-bpelws/bpel_tutorial_cn.html 开始 什么是Bus ...

  9. (转)神经网络和深度学习简史(第一部分):从感知机到BP算法

    深度|神经网络和深度学习简史(第一部分):从感知机到BP算法 2016-01-23 机器之心 来自Andrey Kurenkov 作者:Andrey Kurenkov 机器之心编译出品 参与:chen ...

随机推荐

  1. Intersection(计算几何)

    Intersection Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)To ...

  2. Idiomatic Phrases Game(图论最短路)

    Idiomatic Phrases Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...

  3. POJ 2856 Y2K Accounting Bug【简单暴力】

    链接: http://poj.org/problem?id=2586 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#probl ...

  4. Ubuntu 下安装JDK1.8

    好困,不行了,我要睡觉了,先上图吧!

  5. android控件层次

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...

  6. androidAndroid开发学习--Ionic+Cordova 环境搭建

    我们看 Ionic 能给我们提供什么?  一个样式库,你可以使用它 来 装饰你的 HTML 网页 ,看起来 想 移动程序的 界面,什么 header .content.footer.grid.list ...

  7. Advanced GET 9.1 修正汉化版(免注册、页面加载、保存都正常)

    http://www.55188.com/viewthread.php?tid=2846679 Advanced GET 9.1 修正汉化版(免注册.页面加载.保存都正常) 网上流传的很多GET9.1 ...

  8. java 类中定义接口的调用方法

    public class Human { public interface MyAction { public void getPower(); } } public class Test{ publ ...

  9. shiro3

    1 shiro介绍 1.1 什么是shiro shiro是apache的一个开源框架,是一个权限管理的框架,实现 用户认证.用户授权. spring中有spring security (原名Acegi ...

  10. nuget.org 无法加载源 https://api.nuget.org/v3/index.json 的服务索引 不定时抽风

    今天添加新项目想添加几个工具包,打开NuGet就这样了  发生错误如下: [nuget.org] 无法加载源 https://api.nuget.org/v3/index.json 的服务索引.响应状 ...