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

第一道LCT,调了3天,发现是智障bug,我的青春。。。

主要参考了黄学长的代码,也没啥好说的,反正就是LCT,就当存一份模版好了。

#include <cstdio>const int maxn = 200005;int n, m, t1, t2, t3, ori_tree_fa[maxn];
int left[maxn], right[maxn], fa[maxn], siz[maxn], root;
int stk[maxn], top, pushdown_tem;
bool rev[maxn];inline void pushup(int x) {siz[x] = siz[left[x]] + siz[right[x]] + 1;
}
inline void pushdown(int x) {if (rev[x]) {rev[x] = false;rev[left[x]] = !rev[left[x]];rev[right[x]] = !rev[right[x]];pushdown_tem = left[x];left[x] = right[x];right[x] = pushdown_tem;}
}
inline bool isroot(int x) {return left[fa[x]] != x && right[fa[x]] != x;
}
inline void leftrotate(int x) {int y = fa[x];if (!isroot(y)) {if (y == left[fa[y]]) {left[fa[y]] = x;}else {right[fa[y]] = x;}}fa[x] = fa[y];right[y] = left[x];fa[left[x]] = y;fa[y] = x;left[x] = y;pushup(y);pushup(x);
}
inline void rightrotate(int x) {int y = fa[x];if (!isroot(y)) {if (y == left[fa[y]]) {left[fa[y]] = x;}else {right[fa[y]] = x;}}fa[x] = fa[y];left[y] = right[x];fa[right[x]] = y;fa[y] = x;right[x] = y;pushup(y);pushup(x);
}
inline void splay(int x) {int p;top = 0;stk[top++] = x;for (int i = x; !isroot(i); i = fa[i]) {stk[top++] = fa[i];}for (int i = top - 1; i >= 0; --i) {pushdown(stk[i]);}while (!isroot(x)) {p = fa[x];if (isroot(p)) {if (x == right[p]) {leftrotate(x);}else {rightrotate(x);}}else {if (p == right[fa[p]]) {if (x == right[p]) {leftrotate(p);leftrotate(x);}else {rightrotate(x);leftrotate(x);}}else {if (x == right[p]) {leftrotate(x);rightrotate(x);}else {rightrotate(p);rightrotate(x);}}}}
}
inline void acc(int x) {int y = 0;while (x) {splay(x);right[x] = y;pushup(x);y = x;x = fa[x];}
}
inline void make_root(int x) {acc(x);splay(x);rev[x] = !rev[x];
}
inline void joyn(int x, int y) {make_root(x);fa[x] = y;splay(x);
}
inline void cutt(int x, int y) {make_root(x);acc(y);splay(y);left[y] = fa[x] = 0;pushup(y);
}int main(void) {//freopen("in.txt", "r", stdin);scanf("%d", &n);root = n + 1;for (int i = 1; i <= n; ++i) {scanf("%d", &t2);t2 = i + t2 < root? i + t2: root;siz[i] = 1;fa[i] = ori_tree_fa[i] = t2;}siz[root] = 1;scanf("%d", &m);while (m--) {scanf("%d%d", &t1, &t2);++t2;if (t1 == 1) {make_root(root);acc(t2);splay(t2);printf("%d\n", siz[left[t2]]);}else {scanf("%d", &t3);t3 = t2 + t3 < root? t2 + t3: root;cutt(t2, ori_tree_fa[t2]);joyn(t2, t3);ori_tree_fa[t2] = t3;}}return 0;
}

  我说的那个智障bug是指,splay开时前,pushdown那里,我错写成了

for (int i = x; !isroot(i); i = fa[i]) {stk[top++] = i;
}

  被这个弄了好久。

转载于:https://www.cnblogs.com/ciao-sora/p/6097512.html

bzoj2002 [Hnoi2010]Bounce 弹飞绵羊【LCT】相关推荐

  1. BZOJ2002: [Hnoi2010]Bounce 弹飞绵羊(LCT)

    Description 某天,Lostmonkey发明了一种超级弹力装置,为了在 他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装 ...

  2. BZOJ2002: [Hnoi2010]Bounce 弹飞绵羊

    n<=200000个点,从i会跳到$i+num_i$,保证$num_i>0$,m<=100000个两种操作:一.修改一个$num$:二.问从$i$开始跳多少步跳出这个序列. 大概是L ...

  3. 2002: [Hnoi2010]Bounce 弹飞绵羊

    2002: [Hnoi2010]Bounce 弹飞绵羊 https://www.lydsy.com/JudgeOnline/problem.php?id=2002 分析: 绵羊在弹飞的路径中相当于一棵 ...

  4. AC日记——[HNOI2010]BOUNCE 弹飞绵羊 洛谷 P3203

    [HNOI2010]BOUNCE 弹飞绵羊 思路: SBlct: 代码: #include <bits/stdc++.h> using namespace std; #define max ...

  5. bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊(分块)

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MB Submit: 10761  Solved: 5542 [Su ...

  6. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊

    Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置 ...

  7. [BZOJ 2002][Hnoi2010]Bounce 弹飞绵羊(分块)

    Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置 ...

  8. [HNOI2010]BOUNCE 弹飞绵羊

    题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置设定初始弹力系 ...

  9. 分块-洛谷P3203 [HNOI2010]BOUNCE 弹飞绵羊

    https://www.luogu.org/problem/show?pid=3203#sub 这道题第一次TLEl,然后改了改变成AC: 所以说这种题目,时限卡得很紧,一定要思考理论复杂度和常数的问 ...

最新文章

  1. 输出主键的值 output inserted.id
  2. python堆排序求topn_堆排序和topN算法
  3. 使用telnet命令验证邮箱
  4. Response重定向---javaweb
  5. 改工作空间_打拼六年换的新房,装修花了17万,飘窗改柜子很实用,谁见过?...
  6. 卷积神经网络 训练的结果是什么_射击训练:卷积神经网络识别解剖结构标志位点...
  7. 说说那些死于决斗的大牛
  8. rmi远程代码执行漏洞_微软 Windows DNS Server 远程代码执行漏洞
  9. 无法在驱动器0分区上安装windows 解决方法
  10. 绿盾加密导致Visual Stdio无法使用
  11. Qt QComboBox 下拉框样式修改
  12. 删除shipyard
  13. 计算广告4——用户增长
  14. 借助资本的力量,雷军仅花10年时间成为中国第九大富豪
  15. 测试用例颗粒度实例列举
  16. 【原创】小球碰撞动画
  17. 彼岸花开开彼岸,奈何桥前怎奈何
  18. 时间复杂度:O(log1+log2+...+logn)=O(log(n!))=O(nlogn)
  19. 《DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter》(NeurIPS-2019)论文阅读
  20. 中国KAB创业教育网_需求分析说明书

热门文章

  1. 王爽汇编语言实验7一个很好的解法(转)
  2. Linux bzip2/gzip/zip/tar 命令详解
  3. TSS详解 ——《x86汇编语言:从实模式到保护模式》读书笔记33
  4. Nginx反向代理负载均衡时,验证码不正确
  5. STM32开发 -- md5sum命令
  6. Hi3516A开发--目录分析
  7. Bootloader加载过程分析
  8. 微信终端跨平台组件 Mars 系列(三)连接超时与IPPort排序
  9. 由Android 65K方法数限制引发的思考
  10. 【Android应用保护技术探索之路系列】之一:Android应用保护技术开篇