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发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏 ...
随机推荐
- LeetCode OJ:Binary Tree Right Side View(右侧视角下的二叉树)
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...
- C++中关于strtok()函数的用法
strtok: #include <string.h> char *strtok(char *str, const char *delim); char *strtok_r(char *s ...
- WPF之ContextMenu的命定绑定
在WPF中右击菜单项的XMAL代码是: <ContextMenu x:Key="sampleContextMenu"> <MenuItem Header=&quo ...
- LeetCode 333. Largest BST Subtree
原题链接在这里:https://leetcode.com/problems/largest-bst-subtree/ 题目: Given a binary tree, find the largest ...
- 学习动态性能表(18)--v$system_event
学习动态性能表 第18篇--V$SYSTEM_EVENT 2007.6.13 本视图概括了实例各项事件的等待信息.v$session_wait显示了系统的当前等待项,v$system_event则提 ...
- POJ2976(最大化平均值)
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9329 Accepted: 3271 De ...
- mina写入数据的过程
mina架构图 写数据.读数据触发点: 写数据: 1.写操作很简单,是调用session的write方法,进行写数据的,写数据的最终结果保存在一个缓存队列里面,等待发送,并把当前session放入f ...
- 2016第十三届浙江省赛 D - The Lucky Week
D - The Lucky Week Edward, the headmaster of the Marjar University, is very busy every day and alway ...
- DCloud:temple
ylbtech-DCloud: 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 7.返回顶部 8.返回顶部 9.返回顶部 1 ...
- AWS + Stunnel + Squid ***
[需求] 第一,能***. 第二,在企业网络要能突破端口限制. [原理] 利用AWS提供的一年免费EC2服务,搭建一台自己的VPS,在VPS中利用Stunnel与本机建立加密连接,将本地http请求通 ...