首页 技术 正文
技术 2022年11月20日
0 收藏 888 点赞 4,163 浏览 2200 个字

新建一个N+1的点,飞出去的连到这个上,记size,每次统计x和N+1的链长就可以。

别忘了编号是从0开始的

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<ctime>
#include<set>
#define pa pair<int,int>
#define lowb(x) ((x)&(-(x)))
#define REP(i,n0,n) for(i=n0;i<=n;i++)
#define PER(i,n0,n) for(i=n;i>=n0;i--)
#define MAX(a,b) ((a>b)?a:b)
#define MIN(a,b) ((a<b)?a:b)
#define CLR(a,x) memset(a,x,sizeof(a))
#define rei register int
#define lt ch[x][0]
#define rt ch[x][1]
using namespace std;
const int maxn=;
typedef long long ll; ll rd(){
ll x=;char c=getchar();int neg=;
while(c<''||c>''){if(c=='-') neg=-;c=getchar();}
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return x*neg;
} int N,M;
int fa[maxn],ch[maxn][],siz[maxn],to[maxn];
bool rev[maxn]; inline void update(int x){siz[x]=(lt?siz[lt]:)+(rt?siz[rt]:)+;}
inline void pushrev(int x){
rev[x]^=;swap(lt,rt);
}
inline void pushdown(int x){
if(!rev[x]) return;
if(lt) pushrev(lt);
if(rt) pushrev(rt);
rev[x]=;
}
inline bool isRoot(int x){return ch[fa[x]][]!=x&&ch[fa[x]][]!=x;}
inline bool isRson(int x){return x==ch[fa[x]][];}
inline void rotate(int x){
int f=fa[x],ff=fa[f];bool b=isRson(x);
if(!isRoot(f)) ch[ff][isRson(f)]=x;fa[x]=ff;
if(ch[x][b^]) fa[ch[x][b^]]=f;ch[f][b]=ch[x][b^];
ch[x][b^]=f;fa[f]=x;update(f);update(x);
}
inline void pushdall(int x){
if(!isRoot(x)) pushdall(fa[x]);pushdown(x);
}
inline void splay(int x){
pushdall(x);
while(!isRoot(x)&&!isRoot(fa[x])){
if(isRson(x)==isRson(fa[x])) rotate(fa[x]);
else rotate(x);rotate(x);
}if(!isRoot(x)) rotate(x);
}
inline void access(int x){
for(int y=;x;y=x,x=fa[x]){
splay(x);rt=y;update(x);
}
}
inline void setRoot(int x){
access(x);splay(x);
pushrev(x);
}
inline int getRoot(int x){
access(x);splay(x);
while(lt){
pushdown(x);x=lt;
}return x;
}
inline void link(int x,int y){//x->y
setRoot(x);
access(y);splay(y);fa[x]=y;
}
inline void cut(int x,int y){
setRoot(x);access(y);splay(y);
ch[y][]=fa[x]=;update(y);
}
inline int query(int x,int y){
setRoot(x);
access(y);splay(y);
//printf("%d %d\n",ch[y][0],ch[y][1]);
return siz[y];
}
inline void change(int x,int k){
if(x+k>N&&x+to[x]>N) return;
if(to[x]) cut(x,MIN(x+to[x],N+));
link(x,MIN(x+k,N+));
to[x]=k;
} int main(){
//freopen("3203.in","r",stdin);
rei i,j,k;N=rd();
REP(i,,N) change(i,rd()),siz[i]=;siz[N+]=;
M=rd();REP(i,,M){
j=rd(),k=rd()+;
if(j==) printf("%d\n",query(N+,k)-);
else change(k,rd());
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898