维护两个栈,分别存光标前和光标后的数

再维护前缀和的栈 和 前缀和最大值的栈

注意一下左移,右移,删除到顶了就不操作了

5个操作

I x : 光标处插入x  -----> s1.push(x)

D  : 光标前删除    -----> s1.pop()

L  :  光标左移      -----> s2.push(s1.top())   s1.pop()

R  :  光标右移      -----> s1.push(s2.top())   s2.pop()

Q k : 输出前k个数前缀和最大值

/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std; #define EPS 1e-8
#define MAXN 1000050
#define MOD (int)1e9+7
#define PI acos(-1.0)
#define DINF (1e10)
#define LINF ((1LL)<<50)
#define INF (0x3f3f3f3f)
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max3(a,b,c) (max(max(a,b),c))
#define min3(a,b,c) (min(min(a,b),c))
#define BUG cout<<"BUG! "<<endl
#define line cout<<"--------------"<<endl
#define L(t) (t << 1)
#define R(t) (t << 1 | 1)
#define Mid(a,b) ((a + b) >> 1)
#define lowbit(a) (a & -a)
#define FIN freopen("in.txt","r",stdin)
#define FOUT freopen("out.txt","w",stdout)
#pragma comment (linker,"/STACK:102400000,102400000") // typedef long long LL;
// typedef unsigned long long ULL;
// typedef __int64 LL;
// typedef unisigned __int64 ULL;
// LL gcd(LL a,LL b){ return b?gcd(b,a%b):a; }
// LL lcm(LL a,LL b){ return a*b/gcd(a,b); } /********************* F ************************/
int pstack[MAXN],sstack[MAXN];
int pre[MAXN];
int pmax[MAXN];
int main()
{
//FIN;
//FOUT;
int n ;
while(~scanf("%d",&n)){
int now1 = ,now2 = ;
while(n--){
char ch;
int a;
getchar();
scanf("%c",&ch);
if(ch == 'I'){
scanf("%d",&a);
pstack[now1] = a;
pre[now1] = (now1 == ) ? a : (pre[now1-]+a);
pmax[now1] = (now1 == ) ? a : max(pmax[now1-],pre[now1]);
now1++;
}else if(ch == 'D'){
if(now1 == ) continue;
now1--;
}else if(ch == 'L'){
if(now1 == ) continue;
sstack[now2] = pstack[now1-];
now1--;
now2++;
}else if(ch == 'R'){
if(now2 == ) continue;
pstack[now1] = sstack[now2-];
pre[now1] = (now1 == ) ? sstack[now2-] : (pre[now1-]+sstack[now2-]);
pmax[now1] = (now1 == ) ? sstack[now2-] : max(pmax[now1-],pre[now1]);
now2--;
now1++;
}else if(ch == 'Q'){
scanf("%d",&a);
printf("%d\n",pmax[a-]);
}
}
}
return ;
}

HDU 4699 Editor 维护栈的更多相关文章

  1. HDU 4699 - Editor - [对顶栈]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4699 Problem Description Sample Input8I 2I -1I 1Q 3LD ...

  2. hdu 4699 Editor 模拟栈

    思路:刚开始用STL中的栈,一直RE……,之后改为手动模拟栈操作,在注意点细节就可以了!!! 代码如下: #include<cstdio> #include<cstring> ...

  3. [置顶] hdu 4699 2个栈维护 or 伸展树

    hdu 4699  Editor 题意:对一个数列进行操作,光标位置后面插入一个权值为x的数,删除光标前的那个数,光标左移一位,光标右移一位,求到k位置的最大的前缀和.. 注意这里的k是在光标之前的, ...

  4. HDU 4699 Editor(模拟 对顶栈)

    题目大意: 给定一个整数序列 维护5种操作 次数<1e6 I x: 光标位置插入x 然后光标位于x之后 D: 删除光标前一个数 L: 光标左移 R: 光标右移 Q k: 询问位置k之前的最大前缀 ...

  5. HDU 4699 Editor (2013多校10,1004题)

    Editor Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  6. HDU 4699 Editor(双向链表)

    双向链表直接模拟. 用一个辅助数组maxSum来维护一下前k项中[1,k]的最大和. 因为光标是一格一格的移动,所以每次光标右移的时候动态更新一下即可. 时间复杂度O(n). #include < ...

  7. HDOJ 4699 Editor 对顶栈模拟

    Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...

  8. HDU—4699 Editor 双向链表+子集和

    惨.今天聪哥选了2013 多校10做训练,结果一题都没做出来.这个题目是数据结构,正好是我强项 如果只是插入 删除 光标左右移动,那都小菜,用链表全解决,关键是那个Q k 要求 a1到aq的连续子序列 ...

  9. 【HDU 4699】 Editor

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...

随机推荐

  1. [POI2005]DWU-Double-row(图论?)

    题意 2n 个数站成两排(每个数在 2n个数中最多出现两遍),一次操作可以交换任意一列中两个数,求使每行数不重复的最少操作数. (n<=50000) 题解 说实话,我真没想到图论.(我太菜了) ...

  2. [洛谷P1119][codevs1817]灾后重建

    题目大意:有n个村庄和一些连通两个村庄的双向道路.每个村庄在一个特定的时间修复.没有修复的村庄不能经过.现在有一系列询问,问两个村庄在t时刻的最短路(如果无法到达或两个村庄本身未修复,输出-1). 解 ...

  3. Generational GC (Part one )

    目录 什么是分代垃圾回收 对象对的年龄 新生代对象和老年对象 Ungar的分带垃圾回收 堆的结构 记录集 写入屏障 对象的结构 分配 新生代GC 幸存空间沾满了怎么办? 老年代GC 优缺点 吞吐量得到 ...

  4. C语言调试小技巧

    经常看到有人介绍一些IDE或者像gdb这样的调试器的很高级的调试功能,也听人说过有些牛人做工程的时候就用printf来调试,不用特殊的调试器.特别是在代码经过编译器一些比较复杂的优化后,会变得“难以辨 ...

  5. POJ 3863 Business Center

    Business Center Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Origina ...

  6. vs2010和qt4.8.4配置

    最近项目要求在vs中开发qt程序,安装过后发现代码每天提示功能.由于本人记忆力有限,特在网上收罗了些配置方法. vs安装目录采用默认,qt安装目录:C:\Qt\4.8.4vs 在系统环境变量新建QTD ...

  7. vue25---vue2.0变化

    组件模版: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  8. Delegates, Events, and Anonymous Methods 委托、事件与匿名方法

    http://www.cnblogs.com/r01cn/archive/2012/11/30/2795977.html

  9. springMVC的一些配置解析

    <mvc:annotation-driven /> <!-- 启动注解驱动的Spring MVC功能,注册请求url和注解POJO类方法的映射--> 是一种简写形式,完全可以手 ...

  10. GPT模式下ghost系统 安装方法

    GPT模式下ghost系统 安装方法 1.UEFI进入PE 2.使用diskgenius 软件 分区,选择GPT方式分区 3.使用CGI ghost 系统 文件到安装盘 4.UEFI修复:软件为 BC ...