HDU 4699 Editor (2013多校10,1004题)
2013-08-22 18:21
363 查看
Editor
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 118 Accepted Submission(s): 38
[align=left]Problem Description[/align]
[align=left]Sample Input[/align]
8
I 2
I -1
I 1
Q 3
L
D
R
Q 2
[align=left]Sample Output[/align]
2
3
Hint
The following diagram shows the status of sequence after each instruction:
[align=left]Source[/align]
2013 Multi-University Training Contest 10
[align=left]Recommend[/align]
zhuyuanchen520
这题只要用双向链表模拟一下。
查询最大前缀和,相当于维护一个单调队列。
/* *********************************************** 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 = 1000010; int a[MAXN]; int next[MAXN],pre[MAXN],tot; int NewNode() { next[tot] = -1; pre[tot] = -1; tot++; return tot-1; } int root; int sum[MAXN]; vector<int>vec; int now; int n; void init() { tot = 0; root = NewNode(); vec.clear(); n = now = 0; } void I(int x) { n++; int t = NewNode(); a[t] = x; pre[t] = now; next[t] = next[now]; if(next[now] != -1)pre[next[now]] = t; next[now] = t; now = t; if(n == 1) { sum = x; vec.push_back(n); } else { sum = sum[n-1] + x; int sz = vec.size(); if(sum > sum[vec[sz-1]]) vec.push_back(n); } } void D() { if(n == 0)return; int sz = vec.size(); if(vec[sz-1] == n) vec.pop_back(); n--; int t = pre[now]; next[t] = next[now]; if(next[now] != -1)pre[next[now]] = t; now = t; } void L() { if(n == 0)return; int sz = vec.size(); if(vec[sz-1] == n) vec.pop_back(); now = pre[now]; n--; } void R() { if(next[now] == -1)return; n++; now = next[now]; if(n == 1) { sum = a[now]; vec.push_back(n); } else { int sz = vec.size(); sum = sum[n-1] + a[now]; if(sum > sum[vec[sz-1]]) vec.push_back(n); } } int Q(int k) { int sz = vec.size(); if(vec[sz-1] <= k) return sum[vec[sz-1]]; int t = upper_bound(vec.begin(),vec.end(),k) - vec.begin(); return sum[vec[t-1]]; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int M; int x; char op[10]; while(scanf("%d",&M) == 1) { init(); while(M--) { scanf("%s",&op); if(op[0] == 'I') { scanf("%d",&x); I(x); } else if(op[0] == 'D') D(); else if(op[0] == 'L') L(); else if(op[0] == 'R') R(); else { scanf("%d",&x); printf("%d\n",Q(x)); } } } return 0; }
相关文章推荐
- hdu 4699 Editor 伸展树 treap复习
- HDU 4699 Editor (栈的使用,模拟)
- HDU-4699 Editor 数据结构维护
- hdu 4699 Editor (巧用两个栈)
- HDU 4699 Editor(双向链表)
- hdu 4699 Editor
- HDU 4699 Editor( stack)
- hdu 4699 Editor 模拟栈
- HDU 4699 Editor
- HDU 4699 Editor 树状数组
- hdu 4699 Editor 多校第十场 (模拟)
- hdu 4699 Editor 模拟
- 2013 多校第九场 hdu 4699 Editor(vector OR splay tree)
- hdu 4699 Editor(单调栈)
- hdu 4699 Editor 双栈维护最长前缀
- HDU 4699 Editor (双栈)
- Hdu 4699 Editor(Splay)
- hdu 4699 Editor(Splay)
- HDU 1004 Let the Balloon Rise(map)
- 2016 hdu多校联赛1004 GCD rmq+二分