HDU-4699 Editor 数据结构维护
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4699
题意:开始有一个光标,每次有5中操作:1,光标当前位置插入一个数,2,光标当前位置删除一个,3,光标向左移一位,4,光标向右移动一位,5,询问前面的数列的最大前缀和。
由于每次删除的数都是在当前的光标位置,而且询问的前缀和都是在光标前面的位置,因此问题简化了很多,否则要用Splay tree搞了。我们可以直接用一个链表或者两个栈来维护光标以前的最大前缀和,然后直接模拟操作就可以了。。。
//STATUS:C++_AC_671MS_10824KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
//typedef __int64 LL;
//typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
//const LL LNF=1LL<<60;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int sta1[N][],sta2[N];
int n; int main()
{
// freopen("in.txt","r",stdin);
int i,j,a,top1,top2;
char op[];
while(~scanf("%d",&n))
{
top1=top2=;
sta1[][]=-INF;
while(n--){
scanf("%s",op);
if(op[]=='I'){
scanf("%d",&a);
sta1[++top1][]=a;
sta1[top1][]=sta1[top1-][]+a;
sta1[top1][]=Max(sta1[top1][],sta1[top1-][]);
}
else if(op[]=='D'){
top1--;
}
else if(op[]=='L'){
if(top1<)continue;
sta2[++top2]=sta1[top1--][];
}
else if(op[]=='R'){
if(top2<)continue;
a=sta2[top2--];
sta1[++top1][]=a;
sta1[top1][]=sta1[top1-][]+a;
sta1[top1][]=Max(sta1[top1][],sta1[top1-][]);
}
else {
scanf("%d\n",&a);
printf("%d\n",sta1[a][]);
}
}
}
return ;
}
HDU-4699 Editor 数据结构维护的更多相关文章
- HDU 4699 Editor 维护栈
维护两个栈,分别存光标前和光标后的数 再维护前缀和的栈 和 前缀和最大值的栈 注意一下左移,右移,删除到顶了就不操作了 5个操作 I x : 光标处插入x -----> s1.push(x) ...
- HDU 4699 - Editor - [对顶栈]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4699 Problem Description Sample Input8I 2I -1I 1Q 3LD ...
- 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 < ...
- HDU 4699 Editor(模拟 对顶栈)
题目大意: 给定一个整数序列 维护5种操作 次数<1e6 I x: 光标位置插入x 然后光标位于x之后 D: 删除光标前一个数 L: 光标左移 R: 光标右移 Q k: 询问位置k之前的最大前缀 ...
- HDU—4699 Editor 双向链表+子集和
惨.今天聪哥选了2013 多校10做训练,结果一题都没做出来.这个题目是数据结构,正好是我强项 如果只是插入 删除 光标左右移动,那都小菜,用链表全解决,关键是那个Q k 要求 a1到aq的连续子序列 ...
- hdu 4699 Editor 模拟栈
思路:刚开始用STL中的栈,一直RE……,之后改为手动模拟栈操作,在注意点细节就可以了!!! 代码如下: #include<cstdio> #include<cstring> ...
- [置顶] hdu 4699 2个栈维护 or 伸展树
hdu 4699 Editor 题意:对一个数列进行操作,光标位置后面插入一个权值为x的数,删除光标前的那个数,光标左移一位,光标右移一位,求到k位置的最大的前缀和.. 注意这里的k是在光标之前的, ...
- 【HDU 4699】 Editor
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...
随机推荐
- fill 函数
fill函数的作用是:将一个区间的元素都赋予val值.函数参数:fill(first,last,val);//first为容器的首迭代器,last为容器的末迭代器,val为将要替换的值. 例题:给你n ...
- Unity3D开发之查找面板上某个脚本(包括Missing)
原地址:http://blog.csdn.net/lihandsome/article/details/24265411 有时候我们需要知道某个脚本在场景上面哪里用到,或者那个脚本被删除了但又没有把相 ...
- 最短路径算法之二——Dijkstra算法
Dijkstra算法 Dijkstra算法主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止. 注意该算法要求图中不存在负权边. 首先我们来定义一个二维数组Edge[MAXN][MAXN]来存储 ...
- python学习笔记八--动态类型
一.变量,对象,引用: 1. 变量: 2. 对象:均包含了一个头部信息,有以下两部分内容 a.对象的数据类型, b.引用计数器:纪录当前引用货指向该对象的数量,一旦计数器被清零,该对象的内存空间就会被 ...
- 主机头部分 www有和无是有区别的
关于主机部分www的问题: case 1: frontend web_service bind *:80 bind *:443 ssl crt /etc/haproxy/cert.pem acl ww ...
- How to change data dir of mysql?
# 1 copy orgin data dir of mysql to new one cp -R /var/lib/mysql /mysqldata chown mysql:mysql -R /my ...
- xp主机用VMware9和10安装Ubuntu12.04后无法进入图像界面
xp主机用VMware9和10安装Ubuntu12.04后无法进入图像界面 备注:虚拟机安装Ubuntu12.04 64位版本 刚开始我用VMware-workstation-full-8.0.3来安 ...
- poj 1836 Alignment(dp)
题目:http://poj.org/problem?id=1836 题意:最长上升子序列问题, 站队,求踢出最少的人数后,使得队列里的人都能看到 左边的无穷远处 或者 右边的无穷远处. 代码O(n^2 ...
- [原]Unity3D深入浅出 - 物理引擎之刚体部件(Rigidbody)
在虚拟世界中,任何物体都是没有活力的,要想变的真实,Rigidbody是必不可少的组件,下面介绍Rigidbody的各个属性: Mass:质量 Drag:阻力,对象在运动时遇到的空气阻力,0表示没有空 ...
- ajax post提交数据, input type=submit 返回prompt aborted by user
添加 return false;否则就报prompt aborted by user异常