HDU 4699 Editor 维护栈
2024-08-31 16:36:37
维护两个栈,分别存光标前和光标后的数
再维护前缀和的栈 和 前缀和最大值的栈
注意一下左移,右移,删除到顶了就不操作了
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 ;
}
最新文章
- windows命令——taskkill
- Solr 4.0 部署实例教程
- 关于启用 HTTPS 的一些经验分享(一)
- java System.arraycopy 数组复制和合并
- oracle sql rank dense_rank row_number fisrt last
- Winform开发框架之介绍
- 【niubi-job——一个分布式的任务调度框架】----FAQ文档
- Linux+mysql+apache+php+wordpress搭建个人空间
- eclipse启动问题
- javap 可以打印出用于jni调用的java函数的签名信息
- Java笔记(三)&hellip;&hellip;基础语法
- RocksDB介绍:一个比LevelDB更彪悍的引擎
- C# DataTable几个常用的查询表达式【转】
- js获取input file完整路径的方法
- artTemplate模板
- 怎么利用GitHub
- 不安分的this
- [OpenCV]直线拟合
- 廖雪峰 JavaScript 学习笔记(判断、循环)
- [20171130]关于rman备份疑问.txt