HDU 4699 Editor (2013多校10,1004题)
Editor
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 118 Accepted Submission(s): 38

I 2
I -1
I 1
Q 3
L
D
R
Q 2
3
The following diagram shows the status of sequence after each instruction:
这题只要用双向链表模拟一下。
查询最大前缀和,相当于维护一个单调队列。
/* ***********************************************
Author :kuangbin
Created Time :2013/8/22 13:38:35
File Name :F:\2013ACM练习\2013多校10\1004.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MAXN = ; int a[MAXN];
int next[MAXN],pre[MAXN],tot;
int NewNode()
{
next[tot] = -;
pre[tot] = -;
tot++;
return tot-;
}
int root;
int sum[MAXN];
vector<int>vec;
int now;
int n;
void init()
{
tot = ;
root = NewNode();
vec.clear();
n = now = ;
} void I(int x)
{
n++;
int t = NewNode();
a[t] = x;
pre[t] = now;
next[t] = next[now];
if(next[now] != -)pre[next[now]] = t;
next[now] = t;
now = t;
if(n == )
{
sum[n] = x;
vec.push_back(n);
}
else
{
sum[n] = sum[n-] + x;
int sz = vec.size();
if(sum[n] > sum[vec[sz-]])
vec.push_back(n);
}
}
void D()
{
if(n == )return;
int sz = vec.size();
if(vec[sz-] == n)
vec.pop_back();
n--;
int t = pre[now];
next[t] = next[now];
if(next[now] != -)pre[next[now]] = t;
now = t;
}
void L()
{
if(n == )return;
int sz = vec.size();
if(vec[sz-] == n)
vec.pop_back();
now = pre[now];
n--;
}
void R()
{
if(next[now] == -)return;
n++;
now = next[now];
if(n == )
{
sum[n] = a[now];
vec.push_back(n);
}
else
{
int sz = vec.size();
sum[n] = sum[n-] + a[now];
if(sum[n] > sum[vec[sz-]])
vec.push_back(n);
}
} int Q(int k)
{
int sz = vec.size();
if(vec[sz-] <= k)
return sum[vec[sz-]];
int t = upper_bound(vec.begin(),vec.end(),k) - vec.begin();
return sum[vec[t-]];
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int M;
int x;
char op[];
while(scanf("%d",&M) == )
{
init();
while(M--)
{
scanf("%s",&op);
if(op[] == 'I')
{
scanf("%d",&x);
I(x);
}
else if(op[] == 'D')
D();
else if(op[] == 'L')
L();
else if(op[] == 'R')
R();
else
{
scanf("%d",&x);
printf("%d\n",Q(x));
}
}
}
return ;
}
HDU 4699 Editor (2013多校10,1004题)的更多相关文章
- HDU 4669 Mutiples on a circle (2013多校7 1004题)
Mutiples on a circle Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Oth ...
- HDU 4705 Y (2013多校10,1010题,简单树形DP)
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...
- HDU 4704 Sum (2013多校10,1009题)
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submi ...
- HDU 4696 Answers (2013多校10,1001题 )
Answers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)
Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- HDU 4658 Integer Partition (2013多校6 1004题)
Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU—4699 Editor 双向链表+子集和
惨.今天聪哥选了2013 多校10做训练,结果一题都没做出来.这个题目是数据结构,正好是我强项 如果只是插入 删除 光标左右移动,那都小菜,用链表全解决,关键是那个Q k 要求 a1到aq的连续子序列 ...
- HDU 4741 Save Labman No.004 (2013杭州网络赛1004题,求三维空间异面直线的距离及最近点)
Save Labman No.004 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
随机推荐
- python 协程嵌套
import asyncio import time now = lambda: time.time() async def do_some_work(x): print('Waiting: ', x ...
- 013 GC机制
本文转自:https://www.cnblogs.com/shudonghe/p/3457990.html 最近还是在找工作,在面试某移动互联网公司之前认为自己对Java的GC机制已经相当了解,其他面 ...
- 中高级JAVA面试知识点(个人整理)
JVM运行时数据区域 方法区: 用 于存储虚拟机加载的类信息,常量,静态变量,JIT编译后的代码,所有线程共享 堆:所有线程共享,用来存储实例对象. 虚拟机栈:线程私有,生命周期与线程相同,每个方法被 ...
- linux下C语言编程,include的默认搜索路径
C语言编程时,发现细节的魅力很大.较为详细了看了一下关于include的知识,发现了几点新知: 1.include<头文件名>和include"头文件名" 如:incl ...
- droupout
当训练样本比较少时,为了防止过拟合,可以丢掉一些节点的连接,让某些隐含层结点不工作(即停止更新权值),采用部分连接的方式. 参考:http://blog.csdn.net/on2way/article ...
- 四、ansible主机组定义
1.打开hosts文件 vim /etc/ansible/hosts 2.定义一个主机组 [web-server] 192.168.1.1 3.定义多个组(继承) [web:children] web ...
- appium---【Mac】Appium-Doctor提示WARN:“applesimutils cannot be found”解决方案
报错提示“ applesimutils cannot be found”截图如下: 解决方案: brew tap wix/brew brew install applesimutils 再次执行app ...
- Hadoop案例(四)倒排索引(多job串联)与全局计数器
一. 倒排索引(多job串联) 1. 需求分析 有大量的文本(文档.网页),需要建立搜索索引 xyg pingping xyg ss xyg ss a.txt xyg pingping xyg pin ...
- day2、购物商城
作业:购物商城 商品展示,价格 买,加入购物车 付款,钱不够 代码如下: import codecs #登录接口,用户名密码都正确登录成功,否则失败 def login(your_name,your_ ...
- MFC+WinPcap编写一个嗅探器之零(目录)
零零散散写了三天,完成了编写嗅探器的文章,旨在让自己加深印象,是初学者少走一些弯路.因为先前未接触MFC,之后也不打算精通,完全是0基础,所以文章技术含量不高,但难点基本上都都包括了,凑合这看吧,接下 ...