题目: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

5
1
2
3
4
5
2
ADD 2 4 1
MIN 4 5

Sample Output

5

Source

 
题意:给定一个序列,每次执行一个操作,对于每个min输出即可。
题解:
好个码农题。。。
Splay处理一下区间翻转,区间加上k,区间左右移动(循环序列),区间查询。。。
记得开long long。。。。。。
代码:
 #include<bits/stdc++.h>
using namespace std;
#define MAXN 100010
#define MAXM 100010
#define INF 1e9
#define LL long long
struct node
{
LL left,right,mn,val,size;
}tree[MAXN+MAXM];
LL a[MAXN+MAXM],father[MAXN+MAXM],rev[MAXN+MAXM],tag[MAXN+MAXM];
LL read()
{
LL s=,fh=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')fh=-;ch=getchar();}
while(ch>=''&&ch<=''){s=s*+(ch-'');ch=getchar();}
return s*fh;
}
void Pushup(LL x)
{
LL l=tree[x].left,r=tree[x].right;
tree[x].size=tree[l].size+tree[r].size+;
tree[x].mn=min(min(tree[l].mn,tree[r].mn),tree[x].val);
}
void Build(LL l,LL r,LL f)
{
if(l>r)return;
LL now=l,last=f;
if(l==r)
{
tree[now].val=tree[now].mn=a[l];father[now]=last;
tree[now].size=;
if(l<f)tree[last].left=now;
else tree[last].right=now;
}
LL mid=(l+r)/;
now=mid;
Build(l,mid-,mid);Build(mid+,r,mid);
father[now]=last;tree[now].val=a[mid];
Pushup(now);
if(mid<f)tree[last].left=now;
else tree[last].right=now;
}
/*void Pushup(int x)
{
int l=tree[x].left,r=tree[x].right;
tree[x].size=tree[l].size+tree[r].size+1;
tree[x].mn=min(min(tree[l].mn,tree[r].mn),tree[x].val);
}*/
void rotate(LL x,LL &root)
{
LL y=father[x],z=father[y];
if(y==root)root=x;
else
{
if(tree[z].left==y)tree[z].left=x;
else tree[z].right=x;
}
if(tree[y].left==x)
{
father[x]=z;father[y]=x;tree[y].left=tree[x].right;tree[x].right=y;father[tree[y].left]=y;
}
else
{
father[x]=z;father[y]=x;tree[y].right=tree[x].left;tree[x].left=y;father[tree[y].right]=y;
}
Pushup(y);Pushup(x);
}
void Splay(LL x,LL &root)
{
while(x!=root)
{
int y=father[x],z=father[y];
if(y!=root)
{
if((tree[y].left==x)^(tree[z].left==y))rotate(x,root);
else rotate(y,root);
}
rotate(x,root);
}
}
void Pushdown(LL x)
{
LL l=tree[x].left,r=tree[x].right;
if(tag[x]!=)
{
tag[l]+=tag[x];tag[r]+=tag[x];
tree[l].val+=tag[x];tree[r].val+=tag[x];
tree[l].mn+=tag[x];tree[r].mn+=tag[x];
tag[x]=;
}
if(rev[x]!=)
{
rev[l]^=;rev[r]^=;rev[x]^=;
swap(tree[x].left,tree[x].right);
}
}
LL Find(LL root,LL rank)
{
Pushdown(root);
if(tree[tree[root].left].size+==rank)return root;
else if(rank<=tree[tree[root].left].size)return Find(tree[root].left,rank);
else return Find(tree[root].right,rank-tree[tree[root].left].size-);
}
int main()
{
LL n,m,i,rt,SIZE,l,r,add,x,y,z,L,R,T,X,P;
char fh[];
n=read();
tree[].val=INF;a[]=tree[].mn=INF;
tree[].val=INF;tree[n+].val=INF;
tree[].mn=INF;tree[n+].mn=INF;
a[]=INF;a[n+]=INF;
for(i=;i<=n+;i++)a[i]=read(),tree[i].val=tree[i].mn=INF;
Build(,n+,);
SIZE=n+;rt=(+n+)/;
m=read();
for(i=;i<=m;i++)
{
scanf("\n%s",fh);
if(fh[]=='A')
{
l=read();r=read();add=read();
x=Find(rt,l);y=Find(rt,r+);
Splay(x,rt);Splay(y,tree[x].right);
z=tree[y].left;
tag[z]+=add;tree[z].val+=add;tree[z].mn+=add;
}
else if(fh[]=='R')
{
if(fh[]=='E')
{
l=read();r=read();
x=Find(rt,l);y=Find(rt,r+);
Splay(x,rt);Splay(y,tree[x].right);
z=tree[y].left;
rev[z]^=;
}
else
{
l=read();r=read();T=read();
L=l;R=r;
T=(T%(r-l+)+(r-l+))%(r-l+);
if(T==)continue;
l=r-T+;
x=Find(rt,l);y=Find(rt,r+);
Splay(x,rt);Splay(y,tree[x].right);
z=tree[y].left;
father[z]=;tree[y].left=;
Pushup(y);Pushup(x);
x=Find(rt,L);y=Find(rt,L+);
Splay(x,rt);Splay(y,tree[x].right);
father[z]=y;tree[y].left=z;
Pushup(y);Pushup(x);
}
}
else if(fh[]=='I')
{
X=read();P=read();
x=Find(rt,X+);y=Find(rt,X+);
Splay(x,rt);Splay(y,tree[x].right);
tree[y].left=++SIZE;tree[SIZE].val=P;
father[SIZE]=y;tree[SIZE].size=;
tree[SIZE].mn=P;
Pushup(y);Pushup(x);
}
else if(fh[]=='D')
{
X=read();
x=Find(rt,X);y=Find(rt,X+);
Splay(x,rt);Splay(y,tree[x].right);
z=tree[y].left;tree[y].left=;
tree[z].size=;father[z]=;
//tree[SIZE].val=INF;tree[SIZE].mn=INF;
Pushup(y);Pushup(x);
}
else
{
l=read();r=read();
x=Find(rt,l);y=Find(rt,r+);
Splay(x,rt);Splay(y,tree[x].right);
z=tree[y].left;
printf("%lld\n",tree[z].mn);
}
}
fclose(stdin);
fclose(stdout);
return ;
}

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. ==和equals

  2. Android - This Handler class should be static or leaks might occur.

    今天学习了使用 HTTP协议,从Android客户端往Tomcat服务器端以GET发送请求,途中无意中发现自己写的Handler类被Android提示:This Handler class shoul ...

  3. JavaScript 删除数组重复元素

    unique :function (array){ var n = {}, r = [], len = array.length, val, type; for (var i = 0; i < ...

  4. Vive开发教程汇总

    最近在整理在HTC Vive平台上开发VR应用程序的教程,现在把结果全部汇总在下面的表格里,希望更多的开发者参与到VR内容的开发之中,真的很好玩.现在主流的开发VR应用的引擎是Unity3D和Unre ...

  5. (转)ASP.NET-关于Container dataitem 与 eval方法介绍

    Container是一个数据容器,代表集合类或者dataview中的一行,而Container.dataitem代表该行的数据:所有的container   被存 放在是一个栈堆stack中,自动的将 ...

  6. VBA开发经验总结之一:利用Range对象设计用户界面

    读罢<EXCEL专业开发>,最大的震撼就是著者对VBA技术的追求以及对Excel艺术品般的设计.受到此书著者的启发,也打算把自己在日常开发中一些经验总结出来,一来作为自己的知识储备,二来也 ...

  7. 安装指南【win10下安装fedora】

    系统安装 安装准备 系统:fedora .Win 10 硬件:U盘一枚.PC一台 软件:UltraISO 安装步骤 使用UltraISO将镜像写入U盘 window10使用磁盘管理,空出一个未分配的区 ...

  8. 【python】闰年规则

    公历闰年判定遵循的规律为: 四年一闰,百年不闰,四百年再闰. 公历闰年的简单计算方法(符合以下条件之一的年份即为闰年)1.能被4整除而不能被100整除.2.能被400整除.

  9. 【读书笔记】【CLR via C#】【第一章】The CLR’s Execution Model

    内容提要 本章的目的是对.Net 框架的设计做一个总体的介绍,包括介绍框架中使用的一些技术.定义一些术语.同时会展示从源代码生成应用程序(或者一些包含了一些自定义类型的可以发布的组件),并且会解释程序 ...

  10. WebApi学习总结系列第四篇(路由系统)

    由于工作的原因,断断续续终于看完了<ASP.NET Web API 2 框架揭秘>第二章关于WebApi的路由系统的知识. 路由系统是请求消息进入Asp.net WebApi的第一道屏障, ...