题目:http://poj.org/problem?id=3580

 
SuperMemo
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 13105   Accepted: 4104
Case Time Limit: 2000MS

Description

Your friend, Jackson is invited to a TV show called SuperMemo in which the participant is told to play a memorizing game. At first, the host tells the participant a sequence of numbers, {A1A2, ... An}. Then the host performs a series of operations and queries on the sequence which consists:

  1. ADD x y D: Add D to each number in sub-sequence {Ax ... Ay}. For example, performing "ADD 2 4 1" on {1, 2, 3, 4, 5} results in {1, 3, 4, 5, 5}
  2. REVERSE x y: reverse the sub-sequence {Ax ... Ay}. For example, performing "REVERSE 2 4" on {1, 2, 3, 4, 5} results in {1, 4, 3, 2, 5}
  3. REVOLVE x y T: rotate sub-sequence {Ax ... AyT times. For example, performing "REVOLVE 2 4 2" on {1, 2, 3, 4, 5} results in {1, 3, 4, 2, 5}
  4. INSERT x P: insert P after Ax. For example, performing "INSERT 2 4" on {1, 2, 3, 4, 5} results in {1, 2, 4, 3, 4, 5}
  5. DELETE x: delete Ax. For example, performing "DELETE 2" on {1, 2, 3, 4, 5} results in {1, 3, 4, 5}
  6. MIN x y: query the participant what is the minimum number in sub-sequence {Ax ... Ay}. For example, the correct answer to "MIN 2 4" on {1, 2, 3, 4, 5} is 2

To make the show more interesting, the participant is granted a chance to turn to someone else that means when Jackson feels difficult in answering a query he may call you for help. You task is to watch the TV show and write a program giving the correct answer to each query in order to assist Jackson whenever he calls.

Input

The first line contains (≤ 100000).

The following n lines describe the sequence.

Then follows M (≤ 100000), the numbers of operations and queries.

The following M lines describe the operations and queries.

Output

For each "MIN" query, output the correct answer.

Sample Input

  1. 5
  2. 1
  3. 2
  4. 3
  5. 4
  6. 5
  7. 2
  8. ADD 2 4 1
  9. MIN 4 5

Sample Output

  1. 5

Source

 
题意:给定一个序列,每次执行一个操作,对于每个min输出即可。
题解:
好个码农题。。。
Splay处理一下区间翻转,区间加上k,区间左右移动(循环序列),区间查询。。。
记得开long long。。。。。。
代码:
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define MAXN 100010
  4. #define MAXM 100010
  5. #define INF 1e9
  6. #define LL long long
  7. struct node
  8. {
  9. LL left,right,mn,val,size;
  10. }tree[MAXN+MAXM];
  11. LL a[MAXN+MAXM],father[MAXN+MAXM],rev[MAXN+MAXM],tag[MAXN+MAXM];
  12. LL read()
  13. {
  14. LL s=,fh=;char ch=getchar();
  15. while(ch<''||ch>''){if(ch=='-')fh=-;ch=getchar();}
  16. while(ch>=''&&ch<=''){s=s*+(ch-'');ch=getchar();}
  17. return s*fh;
  18. }
  19. void Pushup(LL x)
  20. {
  21. LL l=tree[x].left,r=tree[x].right;
  22. tree[x].size=tree[l].size+tree[r].size+;
  23. tree[x].mn=min(min(tree[l].mn,tree[r].mn),tree[x].val);
  24. }
  25. void Build(LL l,LL r,LL f)
  26. {
  27. if(l>r)return;
  28. LL now=l,last=f;
  29. if(l==r)
  30. {
  31. tree[now].val=tree[now].mn=a[l];father[now]=last;
  32. tree[now].size=;
  33. if(l<f)tree[last].left=now;
  34. else tree[last].right=now;
  35. }
  36. LL mid=(l+r)/;
  37. now=mid;
  38. Build(l,mid-,mid);Build(mid+,r,mid);
  39. father[now]=last;tree[now].val=a[mid];
  40. Pushup(now);
  41. if(mid<f)tree[last].left=now;
  42. else tree[last].right=now;
  43. }
  44. /*void Pushup(int x)
  45. {
  46. int l=tree[x].left,r=tree[x].right;
  47. tree[x].size=tree[l].size+tree[r].size+1;
  48. tree[x].mn=min(min(tree[l].mn,tree[r].mn),tree[x].val);
  49. }*/
  50. void rotate(LL x,LL &root)
  51. {
  52. LL y=father[x],z=father[y];
  53. if(y==root)root=x;
  54. else
  55. {
  56. if(tree[z].left==y)tree[z].left=x;
  57. else tree[z].right=x;
  58. }
  59. if(tree[y].left==x)
  60. {
  61. father[x]=z;father[y]=x;tree[y].left=tree[x].right;tree[x].right=y;father[tree[y].left]=y;
  62. }
  63. else
  64. {
  65. father[x]=z;father[y]=x;tree[y].right=tree[x].left;tree[x].left=y;father[tree[y].right]=y;
  66. }
  67. Pushup(y);Pushup(x);
  68. }
  69. void Splay(LL x,LL &root)
  70. {
  71. while(x!=root)
  72. {
  73. int y=father[x],z=father[y];
  74. if(y!=root)
  75. {
  76. if((tree[y].left==x)^(tree[z].left==y))rotate(x,root);
  77. else rotate(y,root);
  78. }
  79. rotate(x,root);
  80. }
  81. }
  82. void Pushdown(LL x)
  83. {
  84. LL l=tree[x].left,r=tree[x].right;
  85. if(tag[x]!=)
  86. {
  87. tag[l]+=tag[x];tag[r]+=tag[x];
  88. tree[l].val+=tag[x];tree[r].val+=tag[x];
  89. tree[l].mn+=tag[x];tree[r].mn+=tag[x];
  90. tag[x]=;
  91. }
  92. if(rev[x]!=)
  93. {
  94. rev[l]^=;rev[r]^=;rev[x]^=;
  95. swap(tree[x].left,tree[x].right);
  96. }
  97. }
  98. LL Find(LL root,LL rank)
  99. {
  100. Pushdown(root);
  101. if(tree[tree[root].left].size+==rank)return root;
  102. else if(rank<=tree[tree[root].left].size)return Find(tree[root].left,rank);
  103. else return Find(tree[root].right,rank-tree[tree[root].left].size-);
  104. }
  105. int main()
  106. {
  107. LL n,m,i,rt,SIZE,l,r,add,x,y,z,L,R,T,X,P;
  108. char fh[];
  109. n=read();
  110. tree[].val=INF;a[]=tree[].mn=INF;
  111. tree[].val=INF;tree[n+].val=INF;
  112. tree[].mn=INF;tree[n+].mn=INF;
  113. a[]=INF;a[n+]=INF;
  114. for(i=;i<=n+;i++)a[i]=read(),tree[i].val=tree[i].mn=INF;
  115. Build(,n+,);
  116. SIZE=n+;rt=(+n+)/;
  117. m=read();
  118. for(i=;i<=m;i++)
  119. {
  120. scanf("\n%s",fh);
  121. if(fh[]=='A')
  122. {
  123. l=read();r=read();add=read();
  124. x=Find(rt,l);y=Find(rt,r+);
  125. Splay(x,rt);Splay(y,tree[x].right);
  126. z=tree[y].left;
  127. tag[z]+=add;tree[z].val+=add;tree[z].mn+=add;
  128. }
  129. else if(fh[]=='R')
  130. {
  131. if(fh[]=='E')
  132. {
  133. l=read();r=read();
  134. x=Find(rt,l);y=Find(rt,r+);
  135. Splay(x,rt);Splay(y,tree[x].right);
  136. z=tree[y].left;
  137. rev[z]^=;
  138. }
  139. else
  140. {
  141. l=read();r=read();T=read();
  142. L=l;R=r;
  143. T=(T%(r-l+)+(r-l+))%(r-l+);
  144. if(T==)continue;
  145. l=r-T+;
  146. x=Find(rt,l);y=Find(rt,r+);
  147. Splay(x,rt);Splay(y,tree[x].right);
  148. z=tree[y].left;
  149. father[z]=;tree[y].left=;
  150. Pushup(y);Pushup(x);
  151. x=Find(rt,L);y=Find(rt,L+);
  152. Splay(x,rt);Splay(y,tree[x].right);
  153. father[z]=y;tree[y].left=z;
  154. Pushup(y);Pushup(x);
  155. }
  156. }
  157. else if(fh[]=='I')
  158. {
  159. X=read();P=read();
  160. x=Find(rt,X+);y=Find(rt,X+);
  161. Splay(x,rt);Splay(y,tree[x].right);
  162. tree[y].left=++SIZE;tree[SIZE].val=P;
  163. father[SIZE]=y;tree[SIZE].size=;
  164. tree[SIZE].mn=P;
  165. Pushup(y);Pushup(x);
  166. }
  167. else if(fh[]=='D')
  168. {
  169. X=read();
  170. x=Find(rt,X);y=Find(rt,X+);
  171. Splay(x,rt);Splay(y,tree[x].right);
  172. z=tree[y].left;tree[y].left=;
  173. tree[z].size=;father[z]=;
  174. //tree[SIZE].val=INF;tree[SIZE].mn=INF;
  175. Pushup(y);Pushup(x);
  176. }
  177. else
  178. {
  179. l=read();r=read();
  180. x=Find(rt,l);y=Find(rt,r+);
  181. Splay(x,rt);Splay(y,tree[x].right);
  182. z=tree[y].left;
  183. printf("%lld\n",tree[z].mn);
  184. }
  185. }
  186. fclose(stdin);
  187. fclose(stdout);
  188. return ;
  189. }

Poj 3580-SuperMemo Splay的更多相关文章

  1. poj 3580 SuperMemo

    题目连接 http://poj.org/problem?id=3580 SuperMemo Description Your friend, Jackson is invited to a TV sh ...

  2. POJ 3580 - SuperMemo - [伸展树splay]

    题目链接:http://poj.org/problem?id=3580 Your friend, Jackson is invited to a TV show called SuperMemo in ...

  3. 平衡树(Splay):Splaytree POJ 3580 SuperMemo

    SuperMemo         Description Your friend, Jackson is invited to a TV show called SuperMemo in which ...

  4. POJ 3580 SuperMemo (splay tree)

    SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6841   Accepted: 2268 Case Ti ...

  5. Splay树(多操作)——POJ 3580 SuperMemo

    相应POJ题目:点击打开链接 SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 11309   Accept ...

  6. POJ 3580 SuperMemo (FHQ_Treap)

    题意:让你维护一个序列,支持以下6种操作: ADD x y d: 第x个数到第y个数加d . REVERSE x y : 将区间[x,y]中的数翻转 . REVOLVE x y t :将区间[x,y] ...

  7. POJ 3580 SuperMemo 伸展树

    题意: 维护一个序列,支持如下几种操作: ADD x y D:将区间\([x,y]\)的数加上\(D\) REVERSE x y:翻转区间\([x,y]\) REVOLVE x y T:将区间\([x ...

  8. POJ 3580:SuperMemo(Splay)

    http://poj.org/problem?id=3580 题意:有6种操作,其中有两种之前没做过,就是Revolve操作和Min操作.Revolve一开始想着一个一个删一个一个插,觉得太暴力了,后 ...

  9. 【POJ 3580】SuperMemo Splay

    题意 给定$n$个数,$m$个询问,每次在$[L,R]$区间加上一个数,或者反转一个区间$[L,R]$,或者循环右移区间$[L,R]$共$T$次,或者在第$x$个数后插入一个数$p$,或者删除第$x$ ...

  10. POJ 3580(SuperMemo-Splay区间加)[template:Splay V2]

    SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 11384   Accepted: 3572 Case T ...

随机推荐

  1. Android 设计随便说说

    我曾经搞过应用程序的设计,当时只是读了半本宝典<重构...>,现在看来就这半本九阴真经,收益甚多啊 .再加上这现年工作上的印证,基本上可以拿出喷一下了.当然现在看来当年的项目设计真是很烂了 ...

  2. 配置wamp开发环境【1】

    新手在PHP网站建设时,会使用使用PHP的集成开发环境,这样利于开发和理解!但是做为一个网站开发人员,会独立的配置开发环境这是必须的……因为集成的环境毕竟是固定的,不利于自己的开发.好,废话少说咱现在 ...

  3. 半质数的个数 csdn 英雄会 高校俱乐部

    2·14 情人&元宵节专题:半质数的个数. 题目:质数是大家熟知的概念,我们定义一个半质数的概念:如果一个数恰好是两个质数的乘积(可以相同),则称它为半质数.前几个半质数是 4, 6, 9, ...

  4. USACO 2.2 Subset Sums 集合(subset)

    Description 对于从1到N的连续整集合,能划分成两个子集合,且保证每个集合的数字和是相等的.举个例子,如果N=3,对于{1,2,3}能划分成两个子集合,他们每个的所有数字和是相等的: {3} ...

  5. jcarousellite 实现图片列表滚动

    jcarousel Lite与jcarousel 相比去掉了皮肤的约束,可以自定义的设置前后按钮和选项卡按钮,生成的html更加简洁,文件更小(2k) 下载链接:http://www.gmarwaha ...

  6. sae的kvdb使用注意

    之前没仔细看,原来sae的kvdb使用一定要先调用初始化函数 $kv = new SaeKV(); $kv->init();//必须使用 $kv->set('index', $data);

  7. 精通 Oracle+Python,第 3 部分:数据解析

    进行数据解析的理由不计其数,相关的工具和技巧也同样如此.但是,当您需要用这些数据做一些新的事情时,即使有“合适的”工具可能也是不够的.这一担心对于异类数据源的集成同样存在.用来做这项工作的合适工具迟早 ...

  8. DATE 使用

    DATE 使用 标签(空格分隔): SHELL 使用shell处理文本时经常要使用date,但各种参数经常忘,记录在此: #date 获取当前时间 #date -d "-1 week&quo ...

  9. HIVE:用外连接替代子查询

    由于hive也支持sql,很多人会把hql跟标准sql进行比较,甚至有的时候会直接套用.hive不支持事务也不支持索引,更不支持追加写,但是对于一般的sql都是能够支持的.但是对于一些子查询确实无法支 ...

  10. 学习Swift -- 拓展

    拓展(Extension) 扩展就是向一个已有的类.结构体.枚举类型或者协议类型添加新功能.这包括在没有权限获取原始源代码的情况下扩展类型的能力(即逆向建模).扩展和 Objective-C 中的分类 ...