Description

Input

The first line contains n (n ≤ 100000).

The following n lines describe the sequence.

Then follows M (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

POJ Founder Monthly Contest – 2008.04.13, Yao Jinyu

Solution

  • Splay操作大杂烩!

  • 其它没什么可说的,REVOLVEREVOLVE 操作的话就先算出循环完的位置,

  • 直接把后面剪下来接到前面即可(相当于 CUTCUT 操作)。

Code

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e5+3,inf=1e9;
int root,tot;
int a[N],fa[N],key[N],size[N],s[N][2],mn[N],c[N];
bool rev[N];
inline int read()
{int X=0,w=1; char ch=0;while(ch<'0' || ch>'9') {if(ch=='-') w=-1;ch=getchar();}while(ch>='0' && ch<='9') X=(X<<3)+(X<<1)+ch-'0',ch=getchar();return X*w;
}
inline void write(int x)
{if(x<0) x=-x,putchar('-');if(x>9) write(x/10);putchar(x%10+'0');
}
inline int min(int x,int y)
{return x<y?x:y;
}
inline bool pd(int x)
{return x==s[fa[x]][1];
}
inline void newnode(int &v,int val,int p)
{v=++tot;mn[v]=key[v]=val;size[v]=1,fa[v]=p;s[v][0]=s[v][1]=c[v]=rev[v]=0;
}
inline void add(int v,int val)
{if(v) mn[v]+=val,c[v]+=val,key[v]+=val;
}
inline void update(int v)
{mn[v]=key[v];if(s[v][0]) mn[v]=min(mn[v],mn[s[v][0]]);if(s[v][1]) mn[v]=min(mn[v],mn[s[v][1]]);size[v]=size[s[v][0]]+size[s[v][1]]+1;
}
inline void down(int v)
{if(rev[v]){rev[s[v][0]]^=1,rev[s[v][1]]^=1;swap(s[v][0],s[v][1]);rev[v]=0;}if(c[v]){add(s[v][0],c[v]),add(s[v][1],c[v]);c[v]=0;}
}
inline void build(int &v,int l,int r,int p)
{if(l>r) return;int mid=(l+r)>>1;newnode(v,a[mid],p);build(s[v][0],l,mid-1,v);build(s[v][1],mid+1,r,v);update(v);
}
inline void rotate(int x)
{down(x);int y=fa[x],w=pd(x);if(s[y][w]=s[x][w^1]) fa[s[x][w^1]]=y;if(fa[x]=fa[y]) s[fa[y]][pd(y)]=x;s[fa[y]=x][w^1]=y;update(y);
}
inline void splay(int x,int k)
{for(int y;(y=fa[x])!=k;rotate(x))if(fa[y]!=k) rotate(pd(x)==pd(y)?y:x);update(x);if(!k) root=x;
}
inline int kth(int v,int k)
{down(v);if(size[s[v][0]]+1==k) return v;if(k<=size[s[v][0]]) return kth(s[v][0],k);return kth(s[v][1],k-size[s[v][0]]-1);
}
inline void change(int l,int r,int val)
{splay(kth(root,l-1),0);splay(kth(root,r+1),root);add(s[s[root][1]][0],val);update(s[root][1]),update(root);
}
inline int min_num(int l,int r)
{splay(kth(root,l-1),0);splay(kth(root,r+1),root);return mn[s[s[root][1]][0]];
}
inline void insert(int x,int val)
{splay(kth(root,x),0);splay(kth(root,x+1),root);newnode(s[s[root][1]][0],val,s[root][1]);update(s[root][1]),update(root);
}
inline void delete_num(int x)
{splay(kth(root,x-1),0);splay(kth(root,x),root);fa[s[root][1]=s[s[root][1]][1]]=root;update(s[root][1]),update(root);
}
inline void flip(int l,int r)
{splay(kth(root,l-1),0);splay(kth(root,r+1),root);rev[s[s[root][1]][0]]^=1;
}
inline void cut(int l,int r,int k)
{splay(kth(root,r-k),0);splay(kth(root,r+1),root);int rt=s[s[root][1]][0];s[s[root][1]][0]=0;//deletesplay(kth(root,l-1),0);splay(kth(root,l),root);s[fa[rt]=s[root][1]][0]=rt;update(s[root][1]),update(root);//insert
}
inline void print(int v)
{down(v);if(s[v][0]) print(s[v][0]);if(key[v]<inf) write(key[v]),putchar(' ');if(s[v][1]) print(s[v][1]);
}
int main()
{int n=read();a[1]=a[n+2]=inf;for(int i=2;i<=n+1;i++) a[i]=read();build(root,1,n+2,0);int m=read();while(m--){char ch=getchar();while(ch!='A' && ch!='M' && ch!='R' && ch!='I' && ch!='D') ch=getchar();if(ch=='A'){int x=read()+1,y=read()+1;change(x,y,read());}elseif(ch=='M'){int x=read()+1,y=read()+1;write(min_num(x,y)),putchar('\n');}elseif(ch=='I'){int x=read()+1;insert(x,read());}elseif(ch=='D') delete_num(read()+1); else{while(ch!='S' && ch!='O') ch=getchar();int x=read()+1,y=read()+1;if(ch=='S') flip(x,y); else{int z=read()%(y-x+1);if(z) cut(x,y,z);}}}//print(root);return 0;
}

POJ 3580. SuperMemo相关推荐

  1. POJ 3580 SuperMemo

    http://poj.org/problem?id=3580 题目大意说给你一个数列,有区间同加一个数.区间翻转操作.区间滚动操作.删除一个数.插入一个数,查询区间最小值这些操作. 我是使用Splay ...

  2. POJ 3580 SuperMemo(伸展树的基本操作)

    题目大意:给你六个操作,让你实现这些功能. 解题思路:伸展树的基本应用,用伸展数实现各种功能. SuperMemo Time Limit: 5000MS   Memory Limit: 65536K ...

  3. POJ 3580 SuperMemo 伸展树

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

  4. poj 3580 splay

    维修数列的简化版,要求的操作还是挺多的,运行时间大概1s. 1 #include <iostream> 2 #include <cstring> 3 #include < ...

  5. [kuangbin]各种各样的题单

    [kuangbin]各种各样的题单 专题1 简单搜索 POJ 1321 POJ 2251 POJ 3278 POJ 3279 POJ 1426 POJ 3126 POJ 3087 POJ 3414 F ...

  6. POJ 3268 D-Silver Cow Party

    http://poj.org/problem?id=3268 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

  7. poj 2559 Largest Rectangle in a Histogram 栈

    // poj 2559 Largest Rectangle in a Histogram 栈 // // n个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的 ...

  8. POJ 2528 Mayor's posters(线段树)

    题目大意 贴海报.每张海报的高度都是一样的,唯独宽度不一样.每张海报只能占用整数倍的单位线段长度,贴了 n(n<=10000) 张海报之后,有几张能够看见(有一个角能看见这张海报也算被看见了)? ...

  9. POJ 2226 Muddy Fields 最小点覆盖+加建图(好题)

    题目链接 题目一看就是最小点覆盖,这道题与POJ - 3041 算是一类题,但是3041算是一道十分裸的,因为删除的是整行或者整列,所以图其实是现成的,但是本题的难点就在如何建图. 思路:首先还是尽量 ...

最新文章

  1. Ubuntu 打 deb 包报错(fpm not found、dos2unix not found)
  2. 求1+2+3+…+n
  3. Velocity与JSP技术比较
  4. 微信小程序朋友圈分享图片生成方案实现
  5. 如何解决数据一致性、任务调度、流水号生成等问题?
  6. 3. CMake 系列 - 分模块编译安装项目
  7. gradle 构建 Smack 报错:Can't find android.jar for 8 API. + steps for building android platform
  8. python列表生成式原理_三元表达式/和/或如何在Python中工作/真与假的性质/列表生成/生成器,and,or,执行,原理,True,False,本质,生成式...
  9. Java、Python 竟成区块链主流开发语言?!
  10. Luogu4402 机械排序
  11. jquery 学习笔记(二)
  12. pyecharts 画图
  13. 名帖35 吴叡 隶书《离骚》
  14. 云课堂C++类10T级课程第十课
  15. android 设置默认语言
  16. C3P Software 发布 Cast-Designer V7.7版本
  17. 为什么E-GREEDY算法中e越小,性能会更好
  18. 微信小程序动态添加class样式
  19. 8.14-T1村通网(pupil)
  20. Solidwork 强制卸载

热门文章

  1. python 做词云 -jupyter跟随王树义教程学习
  2. 吴恩达机器学习资源汇总帖
  3. Matlab画图小结(一)
  4. STM32 UART2程序--端口重映射
  5. Linux内核模块的概念和基本的编程方法
  6. 分享 C++命名空间的解释
  7. extjs chart无法在panel中显示_手绘风格的 JS 图表库:Chart.xkcd
  8. [云炬创业基础笔记]第九章企业的法律形态测试8
  9. [云炬创业基础笔记]第二章创业者测试24
  10. 科大星云诗社动态20201118