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 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...
随机推荐
- hdu 4681
将c串从a,b串中删去后求最长公子列 直接暴会超时 #include <cstdio> #include <cstdlib> #include <algorithm&g ...
- mac 用 brew
mac 下用 brew 安装插件, 有重复的不会再次安装,比xmap模式好
- 关于MIM金属注射成型技术知识大全
1.什么是MIM MIM即(Metal Injection Molding)是金属注射成型的简称.是将金属粉末与其粘结剂的增塑混合料注射于模型中的成形方法.它是先将所选粉末与粘结剂进行混合,然后将混合 ...
- altium designer 13 学习之添加汉字
在altium desginer中如果你是想添加英文还是比较方便的,基本直接就可以输入了,但是添加中文就不是那么简单了,下面不介绍下如何在altium designer中快速的添加自己想要的中文 工具 ...
- 组策略限制添加用户作为服务登录导致ITAtomcat服务无法启动(log on as a service)
[故障类型]:ITA tomcat服务器无法启动. [关 键 词]:Logon as a service 作为服务登录 tomcat loggeter [适用版本]:FusionCloud So ...
- 187. Repeated DNA Sequences
题目: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: " ...
- Sqlmap基础(二)
sqlmap.py -r req1.txt --dbms Oracle --risk
- Android 通过广播启动另一个应用的Activity
需求:现在有应用A和应用B,我需要在A应用中启动B应用中的某个Activity 实现:A应用中的Activity发送广播,关键代码如下: String broadcastIntent = " ...
- node.js模块值formidable
模块地址:https://github.com/felixge/node-formidable var formidable = require('formidable'), http = requi ...
- foreach中引用 的问题
在工作中遇到 关于 php foreach 引用的一个问题 简单来说,如下代码 $arr=array('a','b','c' ,'d'); foreach($arr as $k=>&$v ...