bzoj5063
2024-08-30 13:27:53
平衡树
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 ;
}
最新文章
- oracle分组取第一条
- 【Android Studio使用教程6】Execution failed for task &#39;:&#215;&#215;&#215;:compileReleaseAidl&#39;
- Android SDK安装时碰到的问题之解决办法
- Oracle用户system解锁
- 错误:[将截断字符串或二进制数据。\r\n语句已终止。]
- Photoshop快捷键
- AFHTTPRequestOperationManager当一个网络请求加入菊花
- iOS知识点、面试题 之三
- Kibana安装配置
- ORA-02030: can only select from fixed tables/views
- 【转】浅谈常用的几种web攻击方式
- SQL中on条件与where条件的区别
- Selenium和firefox兼容性问题
- [转]深入理解MFC中程序框架
- iOS开发之--iOS APP打包的时候出现的四个选项
- 【BZOJ1935/4822】[Shoi2007]Tree 园丁的烦恼/[Cqoi2017]老C的任务 树状数组
- Apache 配置代理服务
- docker-3-常用命令(上)
- Spring学习(三)—— 自动装配案例分析
- Android4.0系统以上程序不出现菜单键的问题解决
热门文章
- CodeWar---将字符串转换为驼峰命名
- 转:C#并口热敏小票打印机打印位图
- error MIDL2311 解决方法
- UICollectionView 使用 介绍
- pyv8的安装和使用:python中执行js代码
- Hijacking FM Radio with a Raspberry Pi &; Wire
- Python机器学习--聚类
- remove_if的问题
- 生活娱乐 VERYCD的T恤设计大赛
- Razor视图引擎布局 Razor视图引擎的基本概念与法语 SQL Server Mobile 和 .NET 数据访问接口之间的数据类型映射 binary 和 varbinary datetime 和 smalldatetime float 和 real