这个题和$P3203\ $弹飞绵羊基本上完全一致

我的做法是用\(LCT\)维护信息,开一个节点\(fly\),表示到此节点时,小球会弹飞,那么查询弹多少次即为\(siz[fly]-1\)

最后一次落在哪个洞可以用维护链上最大值来解决

一些小细节看代码就行了

\(code:\)

#include<bits/stdc++.h>
#define maxn 400010
using namespace std;
template<typename T> inline void read(T &x)
{
x=0;char c=getchar();bool flag=false;
while(!isdigit(c)){if(c=='-')flag=true;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
if(flag)x=-x;
}
int n,m,flag,root,tot,fly;
int p[maxn],fa[maxn],ch[maxn][2],siz[maxn],ma[maxn],rev[maxn];
bool check(int x)
{
return ch[fa[x]][1]==x;
}
void pushr(int x)
{
rev[x]^=1;swap(ch[x][0],ch[x][1]);
}
void pushup(int x)
{
siz[x]=siz[ch[x][0]]+siz[ch[x][1]]+1;
if(x!=fly) ma[x]=max(x,max(ma[ch[x][0]],ma[ch[x][1]]));
else ma[x]=max(ma[ch[x][0]],ma[ch[x][1]]);
}
void pushdown(int x)
{
if(!rev[x]) return;
pushr(ch[x][0]),pushr(ch[x][1]);
rev[x]=0;
}
bool notroot(int x)
{
return ch[fa[x]][0]==x||ch[fa[x]][1]==x;
}
void rotate(int x)
{
int y=fa[x],z=fa[y],k=check(x),w=ch[x][k^1];
if(notroot(y)) ch[z][check(y)]=x;
fa[x]=z;
ch[y][k]=w;
if(w) fa[w]=y;
ch[x][k^1]=y;
fa[y]=x;
pushup(y);
}
void all(int x)
{
if(notroot(x)) all(fa[x]);
pushdown(x);
}
void splay(int x)
{
all(x);
for(int y;notroot(x);rotate(x))
if(notroot(y=fa[x]))
rotate(check(x)^check(y)?x:y);
pushup(x);
}
void access(int x)
{
for(int y=0;x;y=x,x=fa[x])
splay(x),ch[x][1]=y;
}
void makeroot(int x)
{
access(x),splay(x),pushr(x);
}
void split(int x,int y)
{
makeroot(x),access(y),splay(y);
}
void link(int x,int y)
{
split(x,y),fa[x]=y;
}
void cut(int x,int y)
{
split(x,y),fa[x]=ch[y][0]=0;
}
int main()
{
read(n),read(m);
fly=n+1;
for(int i=1;i<=n;++i)
{
read(p[i]);
if(i+p[i]<=n) link(i,i+p[i]);
else link(i,fly);
}
while(m--)
{
int x,y;
read(flag);
if(flag)
{
read(x);
split(x,fly);
printf("%d %d\n",ma[fly],siz[fly]-1);
}
else
{
read(x),read(y);
if(x+p[x]<=n) cut(x,x+p[x]);
else cut(x,fly);
p[x]=y;
if(x+p[x]<=n) link(x,x+p[x]);
else link(x,fly);
}
}
return 0;
}

题解 CF13E 【Holes】的更多相关文章

  1. CF13E Holes LCT

    CF13E Holes LG传送门 双倍经验题,几乎同[HNOI2010]弹飞绵羊,LCT练手题,LG没有LCT题解于是发一波. 从当前点向目标点连边,构成一棵树,带修改就用LCT动态维护答案,由于不 ...

  2. Codeforces Beta Round #13 E. Holes 分块暴力

    E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Des ...

  3. AtCoder Grand Contest 021完整题解

    提示:如果公式挂了请多刷新几次,MathJex的公式渲染速度并不是那么理想. 总的来说,还是自己太弱了啊.只做了T1,还WA了两发.今天还有一场CodeForces,晚上0点qwq... 题解还是要好 ...

  4. CF 13E Holes

    Holes 题意:现在有一排洞,每个洞有一个弹力,能弹到ai之后的洞,球会弹到这个排的外面,现在有2个操作,0 a b 将第a个洞的弹力设为b, 1 a 将球放入第a个洞,求输出进洞的次数 和 弹出这 ...

  5. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  6. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  7. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  8. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  9. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

随机推荐

  1. spring 整合redis集群中使用@autowire无效问题的解决办法

    1.视频参考黑马32期宜立方商城第6课 redis对于的代码 我们先变向一个redis客户端的接口文件 package com.test; public interface JedisClient { ...

  2. java android 序列号serializable和parcelable

    why 为什么要了解序列化?—— 进行Android开发的时候,无法将对象的引用传给Activities或者Fragments,我们需要将这些对象放到一个Intent或者Bundle里面,然后再传递. ...

  3. 重学ASP.NET Core 中的标记帮助程序

    标记帮助程序是什么 标记帮助程序使服务器端代码可以在 Razor 文件中参与创建和呈现 HTML 元素. 例如,内置的 ImageTagHelper 可以将版本号追加到图片名称.  每当图片发生变化时 ...

  4. java.math.BigDecimal转换double double转换java.math.BigDecimal

    有方法 java.math.BigDecimal.doubleValue() BigDecimal a = new BigDecimal(1000);return a.doubleValue(); p ...

  5. BootstrapDialog.confirm确认对话框

    1. 依赖文件: bootstrap.js bootstrap-dialog.js bootstrap.css bootstrap-dialog.css 2.代码 BootstrapDialog.co ...

  6. sharepoint 2010项目中,ashx页面获取SPContext.Current 为null的原因和解决方法

    //错误的写法 public void ProcessRequest(HttpContext context) { SPSecurity.RunWithElevatedPrivileges(deleg ...

  7. springmvc json乱码问题

    在方法上加上:produces属性即可 @RequestMapping(produces = "application/json;charset=utf-8")

  8. 02.RabbitMQ整合springboot简单使用

    1.添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  9. Howdoo中文社区AMA总结(10月21日)

    10月21日Howdoo举办了中文社区的首次AMA活动,CEO -David Brierley和CMO -Jason Sibley加入到社群中与大家交流并回答社区成员的相关问题. 以下是精选的问题总结 ...

  10. JavaScript图形实例:随机SierPinski三角形

    在“JavaScript图形实例:SierPinski三角形”中,我们介绍了SierPinski三角形的基本绘制方法,在“JavaScript图形实例:迭代函数系统生成图形”一文中,介绍了采用IFS方 ...