rt,块大小要多少才能过?
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=1e5+5,maxblock=sqrt(maxn);
int n,m,ans,a[maxn],pos[maxn],cnt[maxn],tot,len,to[maxn],L[maxblock],R[maxblock],lst;
void init(){
len=sqrt(n);
tot=n/len;
for(int i=1;i<=tot;i++){
L[i]=(i-1)*len+1;
R[i]=i*len;
}
if(R[tot]<n) tot++,L[tot]=R[tot-1]+1,R[tot]=n;
for(int i=1;i<=tot;i++){
for(int j=R[i];j>=L[i];j--){
pos[j]=i;
if(a[j]+j>R[i]) cnt[j]=1,to[j]=j+a[j];
else cnt[j]+=cnt[j+a[j]]+1,to[j]=to[j+a[j]];
}
}
}
void query(int x){
ans=0;
lst=x;
while(x<=n){
ans+=cnt[x];
x=to[x];
if(x<=n) lst=x;
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
init();
while(m--){
int op,x,y;
scanf("%d%d",&op,&x);
if(op){
query(x);
printf("%d %d\n",lst,ans);
}
else{
scanf("%d",&y);
a[x]=y;
int now=pos[x];
for(int i=R[now];i>=L[now];i--) to[i]=cnt[i]=0;
for(int i=R[now];i>=L[now];i--){
if(a[i]+i>R[now]) cnt[i]=1,to[i]=i+a[i];
else cnt[i]+=cnt[i+a[i]]+1,to[i]=to[i+a[i]];
}
}
}
return 0;
}