萌田薰子 @ 2018-10-28 22:03:52
为什么强调呢 因为我真的很蒟啊
splay不会区间翻有没有大佬帮忙看看的QAQ
#include <cstdio>
using namespace std;
const int MAXN = 100010;
struct splay {
int son[2],fa,laz;
} e[MAXN];
int ans[MAXN],root,tot;
inline int re()
{
char q = getchar(); int x = 0;
while (q < '0' || q > '9') q = getchar();
while ('0' <= q && q <= '9')
x = (x << 3) + (x << 1) + q - (3 << 4),q = getchar();
return x;
}
inline void build(int l,int r,int f)
{
if (l > r) return;
int mid = (l + r) >> 1;
e[f].son[mid > f] = mid;
e[mid].fa = f;
if (l == r) return;
build(l,mid - 1,mid);
build(mid + 1,r,mid);
}
inline void swap(int x)
{
int bot = e[x].son[0];
e[x].son[0] = e[x].son[1];
e[x].son[1] = bot;
e[e[x].son[0]].laz ^= 1;
e[e[x].son[1]].laz ^= 1;
}
inline void rotate(int x)
{
if (e[x].laz) swap(x);
int y = e[x].fa,z = e[y].fa,mode = e[y].son[0] == x;
e[z].son[e[z].son[1] == y] = x;
e[x].fa = z;
e[y].son[mode ^ 1] = e[x].son[mode];
e[e[x].son[mode]].fa = y;
e[x].son[mode] = y;
e[y].fa = x;
}
inline void splay(int x,int top)
{
while (e[x].fa != top)
{
int y = e[x].fa,z = e[y].fa;
if (z != top) {
if ((e[y].son[0] == x) ^ (e[z].son[0] == y)) rotate(x);
else rotate(y);
}
rotate(x);
}
}
inline void get(int x)
{
if (e[x].laz) swap(x);
if (e[x].son[0]) get(e[x].son[0]);
ans[++tot] = x;
if (e[x].son[1]) get(e[x].son[1]);
}
int main()
{
int n = re(),m = re(),i,j;
root = (n + 3) >> 1;
build(1,n + 2,0);
e[0].son[0] = 0;
e[0].son[1] = 0;
while (m--)
{
int i = re(),j = re();
splay(i,0),root = i;
splay(j + 2,root);
e[e[e[root].son[1]].son[0]].laz ^= 1;
}
get(root);
for (int a = 2 ; a <= n + 1 ; ++ a) printf("%d ",ans[a] - 1);
return 0;
}
by ouuan @ 2018-10-28 22:05:23
您太ju了%%%
by 萌田薰子 @ 2018-10-28 22:07:50
@ouuan 您太jù了orz
by 花里心爱 @ 2018-10-28 22:10:48
不会splay……
帮不了你了
by ouuan @ 2018-10-28 22:11:07
@一之濑琴美 应该Splay第k大而不是k号节点吧...翻转后顺序不是序号QAQ
by 萌田薰子 @ 2018-10-28 22:12:44
@Irressey 嗯实在不行我还可以膜标
by 萌田薰子 @ 2018-10-28 22:13:21
@ouuan 我我我翻不是按位置的吗QAQ
by ouuan @ 2018-10-28 22:16:31
@一之濑琴美 您连kth()都没有QAQ,您不是按编号翻的吗
by 萌田薰子 @ 2018-10-28 22:21:09
@ouuan 其实我不太能理解您的意思QvQ(感觉要变成神仙聊天了)
by 萌田薰子 @ 2018-10-28 22:21:43
突然不知所措
by ouuan @ 2018-10-28 22:23:49
@一之濑琴美 Splay(x,goal)是把x号节点旋转到goal的儿子处,应该转kth(x)而不是xQAQ
(摘自我的代码)
void rever(int l,int r)
{
int ll=kth(l);
int rr=kth(r+2);
splay(ll,0);
splay(rr,ll);
s[s[rr].ch[0]].tag^=1;
swap(s[s[rr].ch[0]].ch[0],s[s[rr].ch[0]].ch[1]);
}