平衡树

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的更多相关文章

  1. 【BZOJ5063】旅游 Splay

    [BZOJ5063]旅游 Description 小奇成功打开了大科学家的电脑. 大科学家打算前往n处景点旅游,他用一个序列来维护它们之间的顺序.初 始时,序列为1,2,...,n. 接着,大科学家进 ...

  2. BZOJ5063旅游——非旋转treap

    题目描述 小奇成功打开了大科学家的电脑. 大科学家打算前往n处景点旅游,他用一个序列来维护它们之间的顺序.初 始时,序列为1,2,...,n. 接着,大科学家进行m次操作来打乱顺序.每次操作有6步: ...

随机推荐

  1. Nginx官方配置文档收集

    官方入口: https://www.nginx.com/resources/wiki/start/#pre-canned-configurations http://nginx.org/en/docs ...

  2. 【powerdesign】从mysql数据库导出到powerdesign,生成数据字典

    使用版本powerdesign16.5,mysql 5.5,windows 64 =========================================================== ...

  3. BUPT复试专题—分数加法(2014网研)

    题目描述 求2^-a + 2^-b,其中a和b均为正整数,结果用最简分数表示 输入 第一行为测试数据的组数T (1~400).请注意,任意两组测试数据之间相互独立的.每组测试数据一行,包含两个整数a和 ...

  4. 一致性hash算法在memcached中的使用

    一.概述 1.我们的memcacheclient(这里我看的spymemcache的源代码).使用了一致性hash算法ketama进行数据存储节点的选择.与常规的hash算法思路不同.仅仅是对我们要存 ...

  5. 【转载】读懂IL代码就这么简单 (一)

    一前言 感谢 @冰麟轻武 指出文章的错误之处,现已更正 对于IL代码没了解之前总感觉很神奇,初一看完全不知所云,只听高手们说,了解IL代码你能更加清楚的知道你的代码是如何运行相互调用的,此言一出不明觉 ...

  6. Table tr 的隔行变色

    <style type="text/css">    table{border-collapse:collapse;border:1px solid #999;} td ...

  7. JAVA 保留两位小数

    package com.oracle.pojo; import java.math.BigDecimal; import java.text.DecimalFormat; import java.te ...

  8. 依据iPhone6设计稿动态计算rem值

    rem 单位在做移动端的h5开发的时候是最常常使用的单位. 为解决自适应的问题.我们须要动态的给文档的更节点加入font-size 值.使用mediaquery 能够解决问题,可是每个文件都引用一大串 ...

  9. JAVA WEB学习笔记(二):Tomcat服务器的安装及配置

    一.Tomcat的下载及安装. 前往Tomcat官网下载安装包或者免安装压缩包.链接http://tomcat.apache.org/ 这里,我选择的是Tomcat8.0,而不是最新的Tomcat9. ...

  10. TestNG demo

    下载TestNG的归档文件 下载最新版本的TestNG的jar文件,详细请点击访问 http://www.testng.org..在写这篇教程的时候,我下载TestNG中-6.8.jar,并将 tes ...