HDU 4699 Editor 维护栈
维护两个栈,分别存光标前和光标后的数
再维护前缀和的栈 和 前缀和最大值的栈
注意一下左移,右移,删除到顶了就不操作了
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 维护栈的更多相关文章
- HDU 4699 - Editor - [对顶栈]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4699 Problem Description Sample Input8I 2I -1I 1Q 3LD ...
- hdu 4699 Editor 模拟栈
思路:刚开始用STL中的栈,一直RE……,之后改为手动模拟栈操作,在注意点细节就可以了!!! 代码如下: #include<cstdio> #include<cstring> ...
- [置顶] hdu 4699 2个栈维护 or 伸展树
hdu 4699 Editor 题意:对一个数列进行操作,光标位置后面插入一个权值为x的数,删除光标前的那个数,光标左移一位,光标右移一位,求到k位置的最大的前缀和.. 注意这里的k是在光标之前的, ...
- HDU 4699 Editor(模拟 对顶栈)
题目大意: 给定一个整数序列 维护5种操作 次数<1e6 I x: 光标位置插入x 然后光标位于x之后 D: 删除光标前一个数 L: 光标左移 R: 光标右移 Q k: 询问位置k之前的最大前缀 ...
- HDU 4699 Editor (2013多校10,1004题)
Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- HDU 4699 Editor(双向链表)
双向链表直接模拟. 用一个辅助数组maxSum来维护一下前k项中[1,k]的最大和. 因为光标是一格一格的移动,所以每次光标右移的时候动态更新一下即可. 时间复杂度O(n). #include < ...
- HDOJ 4699 Editor 对顶栈模拟
Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...
- HDU—4699 Editor 双向链表+子集和
惨.今天聪哥选了2013 多校10做训练,结果一题都没做出来.这个题目是数据结构,正好是我强项 如果只是插入 删除 光标左右移动,那都小菜,用链表全解决,关键是那个Q k 要求 a1到aq的连续子序列 ...
- 【HDU 4699】 Editor
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...
随机推荐
- exsi从磁盘中加载虚拟机
e
- HDU-2303 The Embarrassed Cryptographer 高精度算法(大数取模)
题目链接:https://cn.vjudge.net/problem/HDU-2303 题意 给一个大数K,和一个整数L,其中K是两个素数的乘积 问K的是否存在小于L的素数因子 思路 枚举素数,大数取 ...
- PKI 信息安全三大特性
[机密性]发送方 接收方明文 M ...
- ArcGIS Engine获得要素的中心点坐标
IPoint centerPoint =new PointClass();//获得要素的中心点 IArea pArea = pFeature.Shape as IArea; pArea.QueryCe ...
- C#日期控件datetimepicker保存空值方法
方法一(推荐): 设置datetimepicker的属性ShowCheckBox为true 在窗口初始化时候,添加代码this.datetimepicker1.Checked = false; 保存日 ...
- ArcGIS api for javascript——加入地图并显示x,y坐标
这个示例报告了用户在地图上悬停和拖拽鼠标的鼠标指针坐标.通过事件监听器来更新鼠标移到的x和y坐标. 下行代码创建了地图: var map = new esri.Map("map") ...
- C#文件拖放至窗口的ListView控件获取文件类型
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 权重轮询调度算法 java版本号
权重轮询调度算法(Weighted Round-Robin Scheduling)--java版本号 因为每台server的配置.安装的业务应用等不同.其处理能力会不一样.所以,我们依据server的 ...
- iOS Code Sign error: Provisioning profile can't be found 解决方式
出现error的过程:在执行另外一个xcode项目重置了code sign.回到原来的项目的时候出现这个error 修复方法: targe-build settings-code signing id ...
- PPAPI中使用Chromium的3D图形接口
使用PPAPI的Graphics 3D接口做了一个小演示样例,鼠标点击插件区域.绘制颜色,效果与ppapi_simple相似. foruok原创,如需转载请关注foruok的微信订阅号"程序 ...