【题目链接】

http://acm.hdu.edu.cn/showproblem.php?pid=4699

【算法】

维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数

在维护栈的同时求最大前缀和,即可

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + ;
const int INF = 2e9; class mstack
{
private :
int tot;
int s[MAXN];
public :
inline void clear()
{
tot = ;
}
inline void push(long long x)
{
tot++;
s[tot] = x;
}
inline void pop()
{
tot--;
}
inline long long top()
{
return s[tot];
}
inline bool empty()
{
return tot == ;
}
} s1,s2; int q,pos;
long long x;
long long sum[MAXN],f[MAXN];
char opt[]; int main()
{ while (scanf("%d",&q) != EOF)
{
f[] = -INF;
s1.clear();
s2.clear();
pos = ;
while (q--)
{
scanf("%s",&opt);
if (opt[] == 'I')
{
scanf("%lld",&x);
s1.push(x);
pos++;
sum[pos] = sum[pos-] + x;
f[pos] = max(f[pos-],sum[pos]);
}
if (opt[] == 'D')
{
if (s1.empty()) continue;
s1.pop();
pos--;
}
if (opt[] == 'L')
{
if (s1.empty()) continue;
x = s1.top();
s1.pop();
s2.push(x);
pos--;
}
if (opt[] == 'R')
{
if (s2.empty()) continue;
x = s2.top();
s2.pop();
s1.push(x);
pos++;
sum[pos] = sum[pos-] + x;
f[pos] = max(f[pos-],sum[pos]);
}
if (opt[] == 'Q')
{
scanf("%lld",&x);
printf("%lld\n",f[x]);
}
}
} return ; }

【HDU 4699】 Editor的更多相关文章

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  8. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

  9. 【HDU 4864】 Task

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4864 [算法] 贪心 不妨将两个数组分别按x从大到小排序 然后枚举每件物品,选择x值大于该物品的且 ...

随机推荐

  1. Mybatis逆向工程使用方法

    使用官方网站的mapper自动生成工具mybatis-generator-core-1.3.2来生成po类和mapper映射文件. 一.mapper生成配置文件 在generatorConfig.xm ...

  2. jQuery鼠标划入划出

    今天来简单的谈谈jQuery的一个划入划出的方法,.首先划入划出能想到的东西有哪些呢,. 1:hover 2:mouseenter/mouseleave 3:mouseover/mouseout. 一 ...

  3. 让浏览器不再显示 https 页面中的 http 请求警报<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" ...

  4. 07C语言程序语句

    C语言程序语句 判断语句 if(表达式) {语句} #include <stdio.h> int main(){ printf("请输入2个数字:"); int a,b ...

  5. (转)Oracle数据库DBA必备基本技能

    [Oracle数据库DBA必备基本技能] shutdown Normal 需要等待所有的用户断开连接 Immediate 等待用户完成当前的语句 Transactional    等待用户完成当前的事 ...

  6. type、object、class之间的关系

    class Foo: pass print(type(int)) # <class 'type'> print(type(str)) # <class 'type'> prin ...

  7. Struts2学习笔记:DMI,多个配置文件,默认Action,后缀

    动态方法调用有三种方法: 1.同一Action多次映射,每个action标签的method对应要调用的方法. 当要调用的方法多了就会增加struts.xml文件的复杂性. 2.struts.Dynam ...

  8. mac 中查看监听程序

    sudo lsof -nP -iTCP -sTCP:LISTEN | grep mysql

  9. lua排序算法

    SEED = ; --随机序列 可任取 NUM = ; --排序规模 --随机序列 初始数据 function GenRnd( seed, n ) --生成随机数 data = {}; local r ...

  10. Hashing - Hard Version

    Hashing - Hard Version Given a hash table of size N, we can define a hash function . Suppose that th ...