#include<cstdio>
#include<algorithm>
#include<queue>
#include<iostream>
#include<cstring>
#include<ctime>
#include<cmath>
using namespace std;
#define maxn 200005
int n;
struct aaa{
int siz,ch[2],flag,fa;
}spl[maxn];
#define ls(x) (spl[x].ch[0])
#define rs(x) (spl[x].ch[1])
#define fa(x) (spl[x].fa)
inline void reverse(int x) {
spl[x].flag^=1;
swap(ls(x),rs(x));
}
inline void push_down(int x) {
if(spl[x].flag) {
if(ls(x)) reverse(ls(x));
if(rs(x)) reverse(rs(x));
spl[x].flag=0;
}
}
inline void update(int x) {
spl[x].siz=spl[ls(x)].siz+spl[rs(x)].siz+1;
}
inline int type(int x) {
if(ls(fa(x))==x) return 0;
if(rs(fa(x))==x) return 1;
return -1;
}
void rotate(int x) {
int y=fa(x),z=fa(y),typo=type(x);
if(type(y)!=-1) {
spl[z].ch[type(y)]=x;
}
spl[x].fa=z;
spl[y].ch[typo]=spl[x].ch[typo^1],spl[ spl[x].ch[typo^1] ].fa=y;
spl[x].ch[typo^1]=y;
spl[y].fa=x;
update(y);
update(x);
}
void down(int x) {
if(type(x)!=-1) down(fa(x));
push_down(x);
}
inline void splay(int x) {
down(x);
for(;type(x)!=-1;rotate(x)) {
if(type(fa(x))!=-1) {
if(type(fa(x))==type(x))
rotate(fa(x));
else
rotate(x);
}
}
}
inline void access(int x) {
int y=0;
while(x) {
splay(x);
rs(x)=y;
update(x);
y=x;
x=fa(x);
}
}
inline void makeroot(int x) {
access(x);
splay(x);
reverse(x);
}
inline void link(int x,int y) {
makeroot(x);
fa(x)=y;
}
inline void split(int x,int y) {
makeroot(x);
access(y);
splay(y);
}
inline void cut(int x,int y) {
split(x,y);
if(fa(x)==y && rs(x)==0) {
fa(x)=0;
ls(y)=0;
}
}
int a[maxn];
void dfs(int u) {
if(ls(u)) dfs(ls(u));
printf("%d ",u);
if(rs(u)) dfs(rs(u));
}
int pre(int x) {
// push_down(x);
x=ls(x);
push_down(x);
while(rs(x)) push_down(x),x=rs(x);
splay(x);
return x;
}
int main() {
int c1=clock();
#ifdef LOCAL
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
//=========================================
int m;
scanf("%d%d",&n,&m);
int maxx=n+1;
for(int i=1;i<=n;i++) {
int x;
spl[i].siz=1;
scanf("%d",&x);
a[i]=x;
x=min(i+x,maxx);
link(i,x);
}
spl[n+1].siz=1;
for(int i=1;i<=m;i++) {
int opt,x,y;
scanf("%d%d",&opt,&x);
if(opt==1) {
// printf("x:%d ",x);
split(x,maxx);
// puts("dfs:");
// dfs(maxx);
// puts("");
printf("%d %d\n",pre(maxx),spl[maxx].siz-1);
} else {
scanf("%d",&y);
int to=min(maxx,x+a[x]);
cut(x,to);
a[x]=y;
link(x,min(maxx,x+y));
}
}
//=========================================
cerr<<"Tmie Used:"<<clock()-c1<<"ms"<<endl;
return 0;
}剪贴板
剪贴板 qa8vgq5j
剪贴板信息
剪贴板信息
- 收录
- 更新