p3203 弹飞绵羊
分析
基本的lct操作,建一个点N表示弹飞出去的点,每次输出N的左子树的大小即可
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define N n+1
#define rep for(int y=0;x;y=x,x=fa[x])
int a[],son[][],siz[],r[],fa[],x[];
inline void up(int x){siz[x]=siz[son[x][]]+siz[son[x][]]+;}
inline void rev(int x){swap(son[x][],son[x][]);r[x]^=;}
inline void pd(int x){
if(r[x]){
if(son[x][])rev(son[x][]);
if(son[x][])rev(son[x][]);
r[x]=;
}
}
inline bool notroot(int x){return son[fa[x]][]==x||son[fa[x]][]==x;}
inline void push_all(int x){if(notroot(x))push_all(fa[x]);pd(x);}
inline int gs(int x){return son[fa[x]][]==x;}
inline void rot(int x){
int y=fa[x],z=fa[y],b=gs(x),c=gs(y),d=son[x][!b];
if(notroot(y))son[z][c]=x;fa[x]=z;if(d)fa[d]=y;
son[y][b]=d;fa[y]=x;son[x][!b]=y;up(y),up(x);
}
inline void splay(int x){
push_all(x);
while(notroot(x)){
int y=fa[x],z=fa[y];
if(notroot(y)){
if(gs(x)==gs(y))rot(y);
else rot(x);
}
rot(x);
}
}
inline void access(int x){rep splay(x),son[x][]=y,up(x);}
inline void makeroot(int x){access(x);splay(x);rev(x);}
inline void spt(int x,int y){makeroot(x);access(y);splay(y);}
inline void link(int x,int y){makeroot(x);fa[x]=y;}
inline void cut(int x,int y){
makeroot(x);access(y);splay(y);
fa[x]=son[y][]=;
up(y);
}
int main(){
int n,m,i,j,k,t;
scanf("%d",&n);
for(i=;i<=n;i++)siz[i]=;
for(i=;i<=n;i++){
scanf("%d",&x[i]);
if(i+x[i]<=n)link(i,i+x[i]);
else link(i,N);
}
scanf("%d",&m);
for(i=;i<=m;i++){
scanf("%d%d",&k,&t);t++;
if(k==)spt(t,N),printf("%d\n",siz[son[N][]]);
else cut(t,min(N,t+x[t])),scanf("%d",&x[t]),link(t,min(N,t+x[t]));
}
return ;
}
p3203 弹飞绵羊的更多相关文章
- P3203 弹飞绵羊-分块
P3203 弹飞绵羊-分块 观察数据范围,发现可以分块.只需要处理每个点跳出所在块后的位置和次数即可.目的是为了加速查询并降低修改复杂度. 对于修改,重构整个块内信息即可. 时间复杂度正确的一批 具体 ...
- 洛谷P3203弹飞绵羊
传送门啦 非常神奇的分块大法. 每块分 √N 个元素 , 预处理出来:对于每个点,记录两个量:一个是它要弹几次才能出它所在的这个块,另外一个是它弹出这个块后到哪个点. 查询操作:一块一块跳过去 单次复 ...
- 【Luogu】P3203弹飞绵羊(分块)
题目链接 正解是LCT但我不会呀蛤蛤蛤蛤蛤 (分块我也没想出来 把区间分成根n个块,每个块内记录两个东西,就是该位置弹多少次能够弹出这个块,以及该位置弹到最后弹出去了之后能够弹到哪里. 然后查询就一个 ...
- P3203 [HNOI2010]弹飞绵羊(LCT)
P3203 [HNOI2010]弹飞绵羊 LCT板子 用一个$p[i]$数组维护每个点指向的下个点. 每次修改时cut*1+link*1就解决了 被弹出界时新设一个点,权为0,作为终点表示出界点.其他 ...
- 洛谷P3203 [HNOI2010] 弹飞绵羊 [LCT]
题目传送门 弹飞绵羊 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置, ...
- 洛谷 P3203 [HNOI2010]弹飞绵羊 解题报告
P3203 [HNOI2010]弹飞绵羊 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一 ...
- [Luogu P3203] [HNOI2010]弹飞绵羊 (LCT维护链的长度)
题面 传送门:洛谷 Solution 这题其实是有类似模型的. 我们先考虑不修改怎么写.考虑这样做:每个点向它跳到的点连一条边,最后肯定会连成一颗以n+1为根的树(我们拿n+1代表被弹出去了).题目所 ...
- P3203 [HNOI2010]弹飞绵羊 —— 懒标记?分块?LCT?...FAQ orz
好久没写博客了哈,今天来水一篇._(:з」∠)_ 题目 :弹飞绵羊(一道省选题) 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏 ...
- P3203 [HNOI2010]弹飞绵羊 —— 懒标记?分块?
好久没写博客了哈,今天来水一篇._(:з」∠)_ 题目 :弹飞绵羊(一道省选题) 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏 ...
随机推荐
- JIRA 的安装和使用
需要的软件 6.0.3-x32.exe jira_6.x_language_zh_CN.jar jira_crack.zip http://pan.baidu.com/s/1dEbpJc1 (从网盘下 ...
- unity 四元数, 两行等价的代码
Vector3 tmpvc; 1. tmpvc = Quaternion.Euler (new Vector3 (0, 30, 0)) * new Vector3 (0, 0, 1); 2. tmpv ...
- uva11292 Dragon of Loowater(排序后贪心)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...
- javascript网页复制功能-复制到粘贴板-兼容多数浏览器(不使用flash)
使用方法:clipBordCopy("hello Copy");//执行后复制hello Copy到粘贴板 通过 var result = clipBordCopy("h ...
- java 实现拖动文件到窗口功能
package tuo; import java.awt.BorderLayout; import java.awt.Color; import java.awt.datatransfer.DataF ...
- 基于SSL的WCF传输安全
[实践]WCF传输安全1:前期准备之证书制作 [实践]WCF传输安全2:基于SSL的WCF匿名客户端 [实践]WCF传输安全3:基于SSL的WCF对客户端验证 [实践]WCF传输安全4:基 ...
- openvswitch以及docker网络
修改docker0的IP,教程写的是/etc/default/docker文件,但是那是过时的配置,真正的配置是在/etc/docker/daemon.json,格式是json的: { "r ...
- CF 622F The Sum of the k-th Powers——拉格朗日插值
题目:http://codeforces.com/problemset/problem/622/F 发现 sigma(i=1~n) i 是一个二次的多项式( (1+n)*n/2 ),sigma(i=1 ...
- BZOJ2342:[SHOI2011]双倍回文
浅谈\(Manacher\):https://www.cnblogs.com/AKMer/p/10431603.html 题目传送门:https://www.lydsy.com/JudgeOnline ...
- [C++] 递归之全排列问题、半数集
一.递归的定义 一个过程或函数在其定义或说明中又直接或间接调用自身的一种方法,它通常把一个大型复杂的问题层层转化为一个原问题相似的规模较小的问题来求解. 二.用递归求解问题的主要步骤 1.找出相似性 ...