传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3223

裸的,打个标记。

#include <cstdio>
#include <algorithm> const int maxn = 100005; int n, m, stk[maxn], top, t1, t2;
int fa[maxn], ch[maxn][2], root, siz[maxn];
char rev[maxn]; inline void pushdown(int x) {
if (rev[x]) {
rev[x] = 0;
rev[ch[x][0]] ^= 1;
rev[ch[x][1]] ^= 1;
std::swap(ch[x][0], ch[x][1]);
}
}
inline void pushup(int x) {
siz[x] = siz[ch[x][0]] + siz[ch[x][1]] + 1;
}
inline void rotate(int x) {
int y = fa[x];
if (y == ch[fa[y]][0]) {
ch[fa[y]][0] = x;
}
else {
ch[fa[y]][1] = x;
}
fa[x] = fa[y];
int dir = x == ch[y][1];
ch[y][dir] = ch[x][dir ^ 1];
fa[ch[x][dir ^ 1]] = y;
ch[x][dir ^ 1] = y;
fa[y] = x;
pushup(y);
pushup(x);
}
inline void splay(int x, int rt) {
int p;
top = 0;
for (int i = x; i != rt; i = fa[i]) {
stk[top++] = i;
}
for (int i = top - 1; ~i; --i) {
pushdown(stk[i]);
}
while (fa[x] != rt) {
p = fa[x];
if (fa[p] == rt) {
rotate(x);
}
else {
if ((p == ch[fa[p]][1]) ^ (x == ch[p][1])) {
rotate(x);
}
else {
rotate(p);
}
rotate(x);
}
}
if (!rt) {
root = x;
}
}
inline int kth(int k) {
int x = root;
pushdown(x);
while (k != siz[ch[x][0]] + 1) {
if (k <= siz[ch[x][0]]) {
x = ch[x][0];
}
else {
k -= siz[ch[x][0]] + 1;
x = ch[x][1];
}
pushdown(x);
}
return x;
}
int make_tree(int left, int right) {
if (left > right) {
return 0;
}
int rt = (left + right) >> 1;
ch[rt][0] = make_tree(left, rt - 1);
fa[ch[rt][0]] = rt;
ch[rt][1] = make_tree(rt + 1, right);
fa[ch[rt][1]] = rt;
pushup(rt);
return rt;
}
void print(int r) {
if (!r) {
return;
}
pushdown(r);
print(ch[r][0]);
if (r != 1 && r != n + 2) {
printf("%d ", r - 1);
}
print(ch[r][1]);
} int main(void) {
//freopen("in.txt", "r", stdin);
scanf("%d%d", &n, &m);
root = make_tree(1, n + 2);
while (m--) {
scanf("%d%d", &t1, &t2);
++t1;
++t2;
t1 = kth(t1 - 1);
t2 = kth(t2 + 1);
splay(t1, 0);
splay(t2, root);
rev[ch[ch[root][1]][0]] ^= 1;
}
print(root);
return 0;
}

  

_bzoj3223 Tyvj 1729 文艺平衡树【Splay】的更多相关文章

  1. BZOJ3223: Tyvj 1729 文艺平衡树 [splay]

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3595  Solved: 2029[Submit][Sta ...

  2. BZOJ 3223: Tyvj 1729 文艺平衡树(splay)

    速度居然进前十了...第八... splay, 区间翻转,用一个类似线段树的lazy标记表示是否翻转 ------------------------------------------------- ...

  3. bzoj 3223: Tyvj 1729 文艺平衡树 (splay)

    链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3223 题面: 3223: Tyvj 1729 文艺平衡树 Time Limit: 10 S ...

  4. BZOJ 3223: Tyvj 1729 文艺平衡树-Splay树(区间翻转)模板题

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 6881  Solved: 4213[Submit][Sta ...

  5. bzoj 3223/tyvj 1729 文艺平衡树 splay tree

    原题链接:http://www.tyvj.cn/p/1729 这道题以前用c语言写的splay tree水过了.. 现在接触了c++重写一遍... 只涉及区间翻转,由于没有删除操作故不带垃圾回收,具体 ...

  6. 【BZOJ3223】 Tyvj 1729 文艺平衡树 Splay

    Description   您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2  ...

  7. bzoj3223: Tyvj 1729 文艺平衡树 splay裸题

    splay区间翻转即可 /************************************************************** Problem: 3223 User: walf ...

  8. BZOJ - 3223 Tyvj 1729 文艺平衡树 (splay/无旋treap)

    题目链接 splay: #include<bits/stdc++.h> using namespace std; typedef long long ll; ,inf=0x3f3f3f3f ...

  9. BZOJ 3223 Tyvj 1729 文艺平衡树 | Splay 维护序列关系

    题解: 每次reverse(l,r) 把l-1转到根,r+1变成他的右儿子,给r+1的左儿子打个标记就是一次反转操作了 每次find和dfs输出的时候下放标记,把左儿子和右儿子换一下 记得建树的时候建 ...

随机推荐

  1. linux字符驱动之poll机制按键驱动

    在上一节中,我们讲解了如何自动创建设备节点,实现一个中断方式的按键驱动.虽然中断式的驱动,效率是蛮高的,但是大家有没有发现,应用程序的死循环里的读函数是一直在读的:在实际的应用场所里,有没有那么一种情 ...

  2. 怎样解读Caffe源代码

    怎样解读Caffe源代码 导读 Caffe是如今非常流行的深度学习库,能够提供高效的深度学习训练.该库是用C++编写.能够使用CUDA调用GPU进行加速.可是caffe内置的工具不一定能够满足用户的全 ...

  3. Office EXCEL 如何保留一位小数,并且单击这个单元格的时候没有一大串小数

    左侧有一列数据,即便我设置单元格格式,把小数位数设为1,看上去的确四舍五入,保留一位小数了,但是实际上我鼠标双击任意单元格,还是原来的数值,这样的数据如果是要发给别人的,肯定不好   如果进行选择性粘 ...

  4. angular react vue 浏览器兼容情况汇总

    一.逻辑层 框架 (1)angular Angular早在1.3版本就抛弃了对ie8的支持. (2)react React 早在0.14.x 版本就抛弃了对ie8的支持. (3)vue Vue就没打算 ...

  5. mac下配置phonegap(cordova)5.1.1开发环境

    眼下最新的cordova的版本号是5.1.1,在mac下搭建开发环境过程例如以下: 1)首先安装NODEJS环境 进入官网: http://nodejs.org/ .眼下的版本号: v0.12.7 点 ...

  6. 竞赛中经常使用的C++写法

    首先是构造函数,重载 #include <iostream> #include <cstdio> #include <cstring> #include <s ...

  7. windows内存管理的机制以及优缺点

    分页存储管理基本思想:用户程序的地址空间被划分成若干固定大小的区域,称为“页”,相应地,内存空间分成若干个物理块,页和块的大小相等.可将用户程序的任一页放在内存的任一块中,实现了离散分配. 分段存储管 ...

  8. js简易美丽的提示框

    <span style="font-size:14px;">function showTips(txt, time, status) { var htmlCon = ' ...

  9. 卸载ubuntu自带openJDK,更改成自己的JDK版本

    你已经成功把jdk1.6.0_03 安装到 /usr/java,并且配置好了系统环境变量 执行 # java -version 时就是 显示jdk1.4.3,是因为你的linux系统有默认的jdk;执 ...

  10. Fresco-Facebook的图片加载框架的使用

    目前常用的开源图片加载框架有:1.Universal-Image-Loader,该项目存在于Github上面https://github.com/nostra13/Android-Universal- ...