【题目链接】

点击打开链接

【算法】

本题也是Splay区间操作的模板题,不过要比BZOJ 3223要稍微复杂一些,做完此题后,我终于对Splay有了更深入的理解,有“拨开云雾见青天”的感觉

本题还是有许多细节的,笔者花了5h才通过了此题

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 100000
const int INF = 2e9; int i,N,M,d,P,x,y,t;
int a[MAXN+];
string opt; template <typename T> inline void read(T &x) {
int f=; x=;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = x * + c - '';
x *= f;
} template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
} template <typename T> inline void writeln(T x) {
write(x);
puts("");
} struct Splay {
int root,total;
struct Node {
int fa,son[],size,add,Min,val;
bool rev;
} Tree[MAXN*+];
inline bool get(int x) {
return Tree[Tree[x].fa].son[] == x;
}
inline void build(int index,int l,int r) {
int mid = (l + r) >> ;
Tree[index].size = ;
Tree[index].add = Tree[index].rev = ;
Tree[index].val = Tree[index].Min = a[mid];
if (l == r) return;
if (l < mid) {
++total;
Tree[index].son[] = total;
Tree[total].fa = index;
build(total,l,mid-);
Tree[index].size += Tree[Tree[index].son[]].size;
Tree[index].Min = min(Tree[index].Min,Tree[Tree[index].son[]].Min);
}
if (mid < r) {
++total;
Tree[index].son[] = total;
Tree[total].fa = index;
build(total,mid+,r);
Tree[index].size += Tree[Tree[index].son[]].size;
Tree[index].Min = min(Tree[index].Min,Tree[Tree[index].son[]].Min);
}
}
inline void new_node(int index,int x,int f) {
Tree[index].rev = ;
Tree[index].size = ;
Tree[index].val = Tree[index].Min = x;
Tree[index].add = ;
Tree[index].fa = f;
Tree[index].son[] = Tree[index].son[] = ;
}
inline int query_pos(int x) {
int index = root;
while (true) {
pushdown(index);
if (x > Tree[Tree[index].son[]].size) {
x -= Tree[Tree[index].son[]].size;
if (x == ) return index;
--x;
index = Tree[index].son[];
} else index = Tree[index].son[];
}
}
inline void pushdown(int index) {
if (Tree[index].rev) {
swap(Tree[index].son[],Tree[index].son[]);
Tree[Tree[index].son[]].rev ^= ;
Tree[Tree[index].son[]].rev ^= ;
Tree[index].rev = ;
}
if (Tree[index].add) {
Tree[Tree[index].son[]].val += Tree[index].add;
Tree[Tree[index].son[]].val += Tree[index].add;
Tree[Tree[index].son[]].add += Tree[index].add;
Tree[Tree[index].son[]].add += Tree[index].add;
Tree[Tree[index].son[]].Min += Tree[index].add;
Tree[Tree[index].son[]].Min += Tree[index].add;
Tree[index].add = ;
}
}
inline void update(int index) {
Tree[index].size = Tree[Tree[index].son[]].size + Tree[Tree[index].son[]].size + ;
Tree[index].Min = Tree[index].val;
if (Tree[index].son[]) Tree[index].Min = min(Tree[index].Min,Tree[Tree[index].son[]].Min);
if (Tree[index].son[]) Tree[index].Min = min(Tree[index].Min,Tree[Tree[index].son[]].Min);
}
inline void splay(int x,int pos) {
int f;
for (f = Tree[x].fa; (f = Tree[x].fa) != pos; rotate(x)) {
if (Tree[f].fa != pos)
rotate(get(f) == get(x) ? (f) : (x));
}
if (!pos) root = x;
}
inline void rotate(int x) {
int f = Tree[x].fa,g = Tree[f].fa,
tmpx = get(x),tmpf = get(f);
pushdown(f); pushdown(x);
if (!f) return;
Tree[f].son[tmpx] = Tree[x].son[tmpx^];
if (Tree[x].son[tmpx^]) Tree[Tree[x].son[tmpx^]].fa = f;
Tree[x].son[tmpx^] = f;
Tree[f].fa = x;
Tree[x].fa = g;
if (g) Tree[g].son[tmpf] = x;
update(f);
update(x);
}
inline void Insert(int p,int val) {
int x = query_pos(p),
y = query_pos(p+);
splay(x,); splay(y,root);
new_node(++total,val,Tree[root].son[]);
Tree[Tree[root].son[]].son[] = total;
update(Tree[root].son[]);
update(root);
}
inline void erase(int p) {
int x = query_pos(p-),
y = query_pos(p+);
splay(x,); splay(y,root);
Tree[Tree[root].son[]].son[] = ;
update(Tree[root].son[]);
update(root);
}
inline void add(int l,int r,int v) {
int x = query_pos(l-),
y = query_pos(r+);
splay(x,); splay(y,root);
Tree[Tree[Tree[root].son[]].son[]].val += v;
Tree[Tree[Tree[root].son[]].son[]].add += v;
Tree[Tree[Tree[root].son[]].son[]].Min += v;
update(Tree[root].son[]);
update(root);
}
inline void reverse(int l,int r) {
int x = query_pos(l-),
y = query_pos(r+);
splay(x,); splay(y,root);
Tree[Tree[Tree[root].son[]].son[]].rev ^= ;
}
inline int query_min(int l,int r) {
int x = query_pos(l-),
y = query_pos(r+);
splay(x,); splay(y,root);
return Tree[Tree[Tree[root].son[]].son[]].Min;
}
inline void revolve(int l,int r,int t) {
int x = query_pos(r-t),
y = query_pos(r+);
splay(x,); splay(y,root);
int tmp = Tree[Tree[root].son[]].son[];
Tree[Tree[root].son[]].son[] = ;
update(Tree[root].son[]);
update(root);
x = query_pos(l-);
y = query_pos(l);
splay(x,); splay(y,root);
Tree[Tree[root].son[]].son[] = tmp;
Tree[tmp].fa = Tree[root].son[];
update(Tree[root].son[]);
update(root);
}
} T; int main() { read(N); T.root = T.total = ;
for (i = ; i <= N + ; i++) read(a[i]);
a[] = a[N+] = INF;
T.build(,,N+); read(M);
while (M--) {
cin >> opt;
if (opt[] == 'A') {
read(x); read(y); read(d);
if (x > y) swap(x,y);
T.add(x+,y+,d);
} else if (opt[] == 'R' && opt[] == 'E' && opt[] == 'V' && opt[] == 'E'){
read(x); read(y);
if (x > y) swap(x,y);
T.reverse(x+,y+);
} else if (opt[] == 'R' && opt[] == 'E' && opt[] == 'V' && opt[] == 'O') {
read(x); read(y); read(t);
if (x > y) swap(x,y);
t = (t % (y - x + ) + y - x + ) % (y - x + );
if (!t) continue;
T.revolve(x+,y+,t);
} else if (opt[] == 'I') {
read(x); read(P);
T.Insert(x+,P);
} else if (opt[] == 'D') {
read(x);
T.erase(x+);
} else if (opt[] == 'M') {
read(x); read(y);
if (x > y) swap(x,y);
writeln(T.query_min(x+,y+));
}
} return ; }

【POJ 3580】 SuperMemo的更多相关文章

  1. 【POJ 3580】SuperMemo Splay

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

  2. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  3. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  4. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  5. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  6. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  7. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  8. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. android studio AndroidManifest

    一.目录结构 1. AndroidManifest.xml 它是一个清单文件,提供应用的基本信息 <?xml version="1.0" encoding="utf ...

  2. javaWeb_Request对象

    首先说一下Http协议 一.Http协议的概念及作用 1.什么是HTTP协议? (HTTP,HyperText Transfer Protocol)超文本传输协议, 是互联网上应用最为广泛的一种网络协 ...

  3. Java并发编程-Executor框架(转)

    本文转自http://blog.csdn.net/chenchaofuck1/article/details/51606224 感谢作者 我们在传统多线程编程创建线程时,常常是创建一些Runnable ...

  4. [转]java中的字符串相关知识整理

    字符串为什么这么重要 写了多年java的开发应该对String不陌生,但是我却越发觉得它陌生.每学一门编程语言就会与字符串这个关键词打不少交道.看来它真的很重要. 字符串就是一系列的字符组合的串,如果 ...

  5. [WASM] Create a New Rust/Webpack Project using the rust-webpack Template

    Previous to this post, we set up our own Rust/wasm project from scratch. The Rust/wasm team ships a ...

  6. Unity3d插件]EasyTouch简单使用方法

    EasyTouch使用 EasyTouch 文件夹[-] 一.效果图 二.操作步骤 1.官方文档上的步骤 2.翻译一下以上的步骤 3.依据官方的这些提示.自己来做一个属于自己的人物遥感控制 对于移动平 ...

  7. 怎样去除JSP页面提示:Cannot return from outside a function or method.

     今天用myeclipse10写JSP页面时出现: Cannot return from outside a function or method. onClick="return ch ...

  8. UWP 新手教程2——怎样实现自适应用户界面

    系列文章 UWP新手教程1--UWP的前世今生 如上文所说的,布局面板依据可用的屏幕空间.指定界面元素的大小和位置. 比如StackPanel 会水平或垂直排列界面元素.Grid 布局与CSS 中的表 ...

  9. 凝视转换(c转换为c++)

    C语言凝视->C++凝视即/*xxxxx*/->//xxxxx 在转换凝视前我们先了解一个概念:什么是有限状态机? 有限状态机FSM是软件上经常使用的一种处理方法,它把复杂的控制逻辑分解成 ...

  10. 小胖说事28------iOS中extern,static和const差别和使用方法

    通俗的讲: extern字段使用的时候,声明的变量为全局变量,都能够调用,也有这样一种比較狭义的说法:extern能够扩展一个类中的变量到还有一个类中: static声明的变量是静态变量,变量值改变过 ...