bzoj5063
平衡树
6个操作做完当然GG了,其实只有两个操作,翻转[A+1,A+B],把这个区间放到C的后面,那么就是基本splay操作了,可是好久没打,又GG了,splay函数写错了。。。
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + ;
namespace IO
{
const int Maxlen = N * ;
char buf[Maxlen], *C = buf;
int Len;
inline void read_in()
{
Len = fread(C, , Maxlen, stdin);
buf[Len] = '\0';
}
inline void fread(int &x)
{
x = ;
int f = ;
while (*C < '' || '' < *C) { if(*C == '-') f = -; ++C; }
while ('' <= *C && *C <= '') x = (x << ) + (x << ) + *C - '', ++C;
x *= f;
}
inline void fread(long long &x)
{
x = ;
long long f = ;
while (*C < '' || '' < *C) { if(*C == '-') f = -; ++C; }
while ('' <= *C && *C <= '') x = (x << ) + (x << ) + *C - '', ++C;
x *= f;
}
inline void read(int &x)
{
x = ;
int f = ; char c = getchar();
while(c < '' || c > '') { if(c == '-') f = -; c = getchar(); }
while(c >= '' && c <= '') { x = (x << ) + (x << ) + c - ''; c = getchar(); }
x *= f;
}
inline void read(long long &x)
{
x = ;
long long f = ; char c = getchar();
while(c < '' || c > '') { if(c == '-') f = -; c = getchar(); }
while(c >= '' && c <= '') { x = (x << 1ll) + (x << 3ll) + c - ''; c = getchar(); }
x *= f;
}
} using namespace IO;
struct node {
int f, rev, sz;
int ch[];
} t[N];
int n, m, root;
int ans[N], size[N];
void update(int x)
{
t[x].sz = t[t[x].ch[]].sz + t[t[x].ch[]].sz + ;
}
bool wh(int x)
{
return x == t[t[x].f].ch[];
}
void pushdown(int x)
{
if(!t[x].rev) return;
t[t[x].ch[]].rev ^= ;
t[t[x].ch[]].rev ^= ;
swap(t[x].ch[], t[x].ch[]);
t[x].rev = ;
}
void up(int x)
{
if(t[x].f) up(t[x].f);
pushdown(x);
}
int build(int l, int r, int f)
{
if(l > r) return ;
int mid = (l + r) >> ;
t[mid].f = f;
t[mid].ch[] = build(l, mid - , mid);
t[mid].ch[] = build(mid + , r, mid);
update(mid);
return mid;
}
void rotate(int x)
{
int f = t[x].f, w = wh(x);
t[x].f = t[f].f;
t[t[f].f].ch[wh(f)] = x;
t[f].ch[w] = t[x].ch[w ^ ];
t[t[x].ch[w ^ ]].f = f;
t[x].ch[w ^ ] = f;
t[f].f = x;
update(f);
update(x);
}
inline void splay(int x, int tar)
{
for(; t[x].f != tar; rotate(x))
if(t[t[x].f].f != tar)
rotate(wh(x) == wh(t[x].f) ? t[x].f : x);
if(!tar) root = x;
}
int find(int x, int k)
{
pushdown(x);
if(t[t[x].ch[]].sz + == k) return x;
if(k <= t[t[x].ch[]].sz) return find(t[x].ch[], k);
return find(t[x].ch[], k - t[t[x].ch[]].sz - );
}
int split(int l, int r)
{
int x = find(root, l - ), y = find(root, r + );
splay(x, );
splay(y, root);
return y;
}
void dfs(int u)
{
if(!u) return;
pushdown(u);
dfs(t[u].ch[]);
ans[++ans[]] = u;
dfs(t[u].ch[]);
}
int main()
{
read_in();
fread(n);
fread(m);
root = build(, n + , );
while(m--)
{
int A, B, C;
fread(A);
fread(B);
fread(C);
int x = split(A + , A + B + ), y = t[x].ch[];
t[y].rev ^= ;
t[y].f = t[x].ch[] = ;
update(x);
update(t[x].f);
int z = split(C + , C + );
t[y].f = z;
t[z].ch[] = y;
update(z);
update(t[z].f);
}
dfs(root);
for(int i = ; i < ans[]; ++i) printf("%d ", ans[i] - );
return ;
}
bzoj5063的更多相关文章
- 【BZOJ5063】旅游 Splay
[BZOJ5063]旅游 Description 小奇成功打开了大科学家的电脑. 大科学家打算前往n处景点旅游,他用一个序列来维护它们之间的顺序.初 始时,序列为1,2,...,n. 接着,大科学家进 ...
- BZOJ5063旅游——非旋转treap
题目描述 小奇成功打开了大科学家的电脑. 大科学家打算前往n处景点旅游,他用一个序列来维护它们之间的顺序.初 始时,序列为1,2,...,n. 接着,大科学家进行m次操作来打乱顺序.每次操作有6步: ...
随机推荐
- AbstractQueuedSynchronizer 队列同步器源码分析
AbstractQueuedSynchronizer 队列同步器(AQS) 队列同步器 (AQS), 是用来构建锁或其他同步组件的基础框架,它通过使用 int 变量表示同步状态,通过内置的 FIFO ...
- C#中值类型和引用类型的差别浅记
C#中值类型和引用类型的差别浅记 在C#中,变量的类型分为两种.各自是值类型和引用类型. 值类型的变量直接存储值,说得更详细一些,就是值类型变量在内存中直接存储它们自身 ...
- hdu 5338 ZZX and Permutations (贪心+线段树+二分)
ZZX and Permutations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/O ...
- hihoCoder 1234 fractal
#1234 : Fractal 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 This is the logo of PKUACM 2016. More specific ...
- iOS_40_核心动画
核心动画之CATransition转场动画 终于效果图: 核心动画之CAKeyFrameAnimation,图标抖动效果 终于效果图: 核心动画之CAAnimationGroup(动画组) 终于效果图 ...
- deepin os 15.4 切换jdk版本
sudo update-alternatives --config javasudo update-alternatives --config javacsudo update-alternative ...
- V-Play 文档翻译 Page
V-Play 文档翻译 Page 翻译:qyvlik 应用的一个页面. VPlayApps 1.0 Inherits: MouseArea Inherited By: ListPage 属性 Item ...
- UR#34. 多项式乘法
#34. 多项式乘法 统计 描述 提交 自定义测试 这是一道模板题. 给你两个多项式,请输出乘起来后的多项式. 输入格式 第一行两个整数 nn 和 mm,分别表示两个多项式的次数. 第二行 n+1n+ ...
- 防sql注入 盲注等措施 ESAPI的使用
SQL注入往往是在程序员编写包含用户输入的动态数据库查询时产生的,但其实防范SQL注入的方法非常简单.程序员只要a)不再写动态查询,或b)防止用户输入包含能够破坏查询逻辑的恶意SQL语句,就能够防范S ...
- 前端遇上Go: 静态资源增量更新的新实践
前端遇上Go: 静态资源增量更新的新实践https://mp.weixin.qq.com/s/hCqQW1F8FngPPGZAisAWUg 前端遇上Go: 静态资源增量更新的新实践 原创: 洋河 美团 ...