博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4699 Editor (2013多校10,1004题)
阅读量:6928 次
发布时间:2019-06-27

本文共 2826 字,大约阅读时间需要 9 分钟。

Editor

Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 118    Accepted Submission(s): 38

Problem Description
 

 

Sample Input
8 I 2 I -1 I 1 Q 3 L D R Q 2
 

 

Sample Output
2 3
Hint
The following diagram shows the status of sequence after each instruction:
 

 

Source
 

 

Recommend
zhuyuanchen520
 

 

 

 

这题只要用双向链表模拟一下。

 

查询最大前缀和,相当于维护一个单调队列。

 

1 /* ***********************************************  2 Author        :kuangbin  3 Created Time  :2013/8/22 13:38:35  4 File Name     :F:\2013ACM练习\2013多校10\1004.cpp  5 ************************************************ */  6   7 #include 
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 using namespace std; 20 const int MAXN = 1000010; 21 22 int a[MAXN]; 23 int next[MAXN],pre[MAXN],tot; 24 int NewNode() 25 { 26 next[tot] = -1; 27 pre[tot] = -1; 28 tot++; 29 return tot-1; 30 } 31 int root; 32 int sum[MAXN]; 33 vector
vec; 34 int now; 35 int n; 36 void init() 37 { 38 tot = 0; 39 root = NewNode(); 40 vec.clear(); 41 n = now = 0; 42 } 43 44 void I(int x) 45 { 46 n++; 47 int t = NewNode(); 48 a[t] = x; 49 pre[t] = now; 50 next[t] = next[now]; 51 if(next[now] != -1)pre[next[now]] = t; 52 next[now] = t; 53 now = t; 54 if(n == 1) 55 { 56 sum[n] = x; 57 vec.push_back(n); 58 } 59 else 60 { 61 sum[n] = sum[n-1] + x; 62 int sz = vec.size(); 63 if(sum[n] > sum[vec[sz-1]]) 64 vec.push_back(n); 65 } 66 } 67 void D() 68 { 69 if(n == 0)return; 70 int sz = vec.size(); 71 if(vec[sz-1] == n) 72 vec.pop_back(); 73 n--; 74 int t = pre[now]; 75 next[t] = next[now]; 76 if(next[now] != -1)pre[next[now]] = t; 77 now = t; 78 } 79 void L() 80 { 81 if(n == 0)return; 82 int sz = vec.size(); 83 if(vec[sz-1] == n) 84 vec.pop_back(); 85 now = pre[now]; 86 n--; 87 } 88 void R() 89 { 90 if(next[now] == -1)return; 91 n++; 92 now = next[now]; 93 if(n == 1) 94 { 95 sum[n] = a[now]; 96 vec.push_back(n); 97 } 98 else 99 {100 int sz = vec.size();101 sum[n] = sum[n-1] + a[now];102 if(sum[n] > sum[vec[sz-1]])103 vec.push_back(n);104 }105 }106 107 108 int Q(int k)109 {110 int sz = vec.size();111 if(vec[sz-1] <= k)112 return sum[vec[sz-1]];113 int t = upper_bound(vec.begin(),vec.end(),k) - vec.begin();114 return sum[vec[t-1]];115 }116 117 118 int main()119 {120 //freopen("in.txt","r",stdin);121 //freopen("out.txt","w",stdout);122 int M;123 int x;124 char op[10];125 while(scanf("%d",&M) == 1)126 {127 init();128 while(M--)129 {130 scanf("%s",&op);131 if(op[0] == 'I')132 {133 scanf("%d",&x);134 I(x);135 }136 else if(op[0] == 'D')137 D();138 else if(op[0] == 'L')139 L();140 else if(op[0] == 'R')141 R();142 else143 {144 scanf("%d",&x);145 printf("%d\n",Q(x));146 }147 }148 }149 return 0;150 }

 

 

 

 

转载地址:http://lzkjl.baihongyu.com/

你可能感兴趣的文章
JS实现类似QQ好友头像hover时显示资料卡的效果
查看>>
离屏渲染优化
查看>>
php 中file_get_contents超时问题的解决方法
查看>>
Oracle 11g RAC oc4j/gsd Offline
查看>>
Ajax下载文件(页面无刷新)
查看>>
[译]Node.js - Event Loop
查看>>
Creating, Stopping, Re-Starting and Deleting a Timer in Oracle Forms
查看>>
laravel 使用 session
查看>>
数据库实例: STOREBOOK > 用户 > 编辑 用户: MGMT_VIEW
查看>>
AjaxPro因为汉字文件夹引发的IE兼容性问题
查看>>
GTK经常使用控件之行编辑( GtkEntry )
查看>>
Picking up Jewels
查看>>
Tween动画TranslateAnimation细节介绍
查看>>
PHP socket 服务器框架集
查看>>
【分词器及自定义】Elasticsearch中文分词器及自定义分词器
查看>>
Ubuntu查看系统版本的方法
查看>>
maven: 打包可运行的jar包(java application)及依赖项处理
查看>>
spark与flume整合
查看>>
数据挖掘工程师笔试及答案整理
查看>>
struts2获取ServletContext对象
查看>>