LCT access完了一定splay再用!!!

悲伤= =

LCT裸题 把调出去设虚点n+1即可

//Love and Freedom.
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 200010
#define ls(x) t[x].son[0]
#define rs(x) t[x].son[1]
#define fa(x) t[x].fa
#define nroot(x) (ls(fa(x))==x||rs(fa(x))==x)
using namespace std; struct node
{
int sz,fa,son[2]; bool rev;
}t[N]; void pushup(int x)
{
t[x].sz = t[ls(x)].sz + t[rs(x)].sz + 1;
} void rotate(int x)
{
if(!x||!nroot(x)) return;
int f = fa(x),gf = fa(f);
int k = (rs(f) == x), p = k^1;
if(nroot(f)) t[gf].son[rs(gf)==f] = x;
t[x].fa = gf; t[f].fa = x;
if(t[x].son[p]) t[t[x].son[p]].fa = f;
t[f].son[k] = t[x].son[p];
t[x].son[p] = f;
pushup(f); pushup(x);
} void pushdown(int x)
{
if(!x || !t[x].rev) return;
swap(ls(x),rs(x));
if(ls(x)) t[ls(x)].rev^=1;
if(rs(x)) t[rs(x)].rev^=1;
t[x].rev^=1;
} void push(int x)
{
if(nroot(x)) push(fa(x));
pushdown(x);
} void splay(int x)
{
push(x);
while(nroot(x))
{
int f = fa(x), gf = fa(f);
if(nroot(gf))
(rs(f)==x)^(rs(gf)==f)?rotate(x):rotate(f);
rotate(x);
}
pushup(x);
} void access(int x)
{
int y = 0;
do
{
//printf("%d\n",x);
splay(x);
t[x].son[1] = y;
pushup(x);
y = x; x = t[x].fa;
}while(x);
} void makeroot(int x)
{
access(x); splay(x); t[x].rev=1;// pushdown(x);
} void link(int x,int y)
{
makeroot(x); t[x].fa = y;
} void cut(int x,int y)
{
makeroot(y); access(x); splay(x);
//printf("%d %d\n",t[y].sz,rs(y));
if(t[x].sz == 2 && ls(x) == y)
t[x].son[0] = 0, t[y].fa = 0,pushup(x);
}
int k[N];
int main()
{
int n,x,y,opt,m;
scanf("%d",&n);
for(int i=1;i<=n+1;i++) t[i].sz=1;
for(int i=1;i<=n;i++)
{
scanf("%d",&k[i]);
if(i+k[i]>n) link(i,n+1);
else link(i,i+k[i]);
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&opt,&x);
//for(int j=1;j<=n+1;j++)
// printf("%d ",t[j].fa);
//printf("\n");
x++;
if(opt==1)
{
makeroot(n+1);
//printf("MMP\n");
//for(int j=1;j<=n+1;j++)
// printf("%d ",t[j].fa);
access(x); splay(x);
//printf("%d %d\n",ls(5),rs(5));
printf("%d\n",t[x].sz-1);
}
else
{
scanf("%d",&y);
cut(x,x+k[x]>n?n+1:x+k[x]);
k[x] = y;
link(x,x+k[x]>n?n+1:x+k[x]);
}
}
return 0;
}

BZOJ2002 [HNOI2010] 弹飞绵羊的更多相关文章

  1. BZOJ2002[Hnoi2010]弹飞绵羊——LCT

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

  2. 【BZOJ2002】弹飞绵羊(Link-Cut Tree)

    [BZOJ2002]弹飞绵羊(Link-Cut Tree) 题面 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lost ...

  3. P3203 [HNOI2010]弹飞绵羊(LCT)

    P3203 [HNOI2010]弹飞绵羊 LCT板子 用一个$p[i]$数组维护每个点指向的下个点. 每次修改时cut*1+link*1就解决了 被弹出界时新设一个点,权为0,作为终点表示出界点.其他 ...

  4. [HNOI2010] 弹飞绵羊 (分块)

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

  5. 洛谷 P3203 [HNOI2010]弹飞绵羊 解题报告

    P3203 [HNOI2010]弹飞绵羊 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一 ...

  6. [BZOJ 2002] [HNOI2010]弹飞绵羊(Link Cut Tree)

    [BZOJ 2002] [HNOI2010]弹飞绵羊(Link Cut Tree) 题面 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一 ...

  7. 「洛谷P3202」[HNOI2010]弹飞绵羊 解题报告

    P3203 [HNOI2010]弹飞绵羊 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一 ...

  8. [Luogu P3203] [HNOI2010]弹飞绵羊 (LCT维护链的长度)

    题面 传送门:洛谷 Solution 这题其实是有类似模型的. 我们先考虑不修改怎么写.考虑这样做:每个点向它跳到的点连一条边,最后肯定会连成一颗以n+1为根的树(我们拿n+1代表被弹出去了).题目所 ...

  9. 【codevs2333】&【BZOJ2002】弹飞绵羊[HNOI2010](分块)

    我其实是在codevs上看到它的题号后才去做这道题的...2333... 题目传送门:codevs:http://codevs.cn/problem/2333/ bzoj:http://www.lyd ...

随机推荐

  1. TabController定义顶部tab切换

    前面通过DefaultTabController组件实现了AppBar里面的顶部导航切换,但是在项目中有数据请求,上拉加载更多等操作的时候,前面的写法,就不是很方便操作,因此,在flutter里面,还 ...

  2. centos环境下安装java环境

    1-上java官网下载rpm安装包 jdk-7u80-linux-i586.rpm 2-新建文件夹,并把jdk-7u80-linux-i586.rpm上传到此文件夹下面 cd /usr/local/ ...

  3. Fault Contract

    The Fault Contract sample demonstrates how to communicate error information from a service to a clie ...

  4. Vagrant 官网文档翻译汇总

    入门 Vagrant 入门 - 项目设置 Vagrant 入门 - box Vagrant 入门 - 启动 vagrant 及 通过 ssh 登录虚拟机 Vagrant 入门 - 同步目录(synce ...

  5. [7期]美少妇(msf)和独角兽(unicorn)

    MSF 全称:metasploit-framework    渗透大杀器,黑客工具排名第一(靠前),尤其在内网中.在校期间大学生先跟本校安全部沟通好,一起实验. 得不到校方理解与认可的上SRC或者自己 ...

  6. 统计Git

    公司需求统计Mos代码行数 方法一:用git #!/bin/bash read -p "输入你要统计mos的分支:" branch Mos_Project=(uusafe-prod ...

  7. BZOJ 3931 (网络流+最短路)

    题面 传送门 分析 考虑网络流 注意到数据包走的是最短路,所以我们只需要考虑在最短路上的边 由于最短路可能有多条,我们先跑一遍Dijkstra,然后再\(O(m)\) 遍历每条边(u,v,w) 如果d ...

  8. pandas分组聚合案例

    美国2012年总统候选人政治献金数据分析 导入包 import numpy as np import pandas as pd from pandas import Series,DataFrame ...

  9. Codeforces - 1195D1 - Submarine in the Rybinsk Sea (easy edition) - 水题

    https://codeforc.es/contest/1195/problem/D1 给\(n\)个等长的十进制数串,定义操作\(f(x,y)\)的结果是"从\(y\)的末尾开始一个一个交 ...

  10. 怎么区分PV、IV、UV以及网站统计名词解释(pv、曝光、点击)

    PV(Page View)访问量,即页面访问量,每打开一次页面PV计数+1,刷新页面也是. IV(Internet Protocol)访问量指独立IP访问数,计算是以一个独立的IP在一个计算时段内访问 ...