1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| #include<iostream> #include<cstdio> #include<cstring> #include<cctype> #include<algorithm> #include<cmath> using namespace std; inline int read(){ int w=0,x=0;char c=getchar(); while(!isdigit(c))w|=c=='-',c=getchar(); while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar(); return w?-x:x; } namespace star { const int maxn=2e5+10; int n,N,out[maxn],last[maxn],cos[maxn],a[maxn],belong[maxn],l[maxn],r[maxn]; void sudo(int l,int r){for(int i=r;i>=l;i--)if(i+a[i]>min(n,r))out[i]=i+a[i],last[i]=i,cos[i]=1;else out[i]=out[i+a[i]],last[i]=last[i+a[i]],cos[i]=1+cos[i+a[i]];} inline void work(){ n=read(); int q=read(); N=sqrt(n); for(int i=1;i<=n;i++) belong[i]=(i-1)/N+1; for(int i=1;i<=n;i++){ if(!l[belong[i]])l[belong[i]]=i; r[belong[i]]=i; } for(int i=1;i<=n;i++)a[i]=read(); for(int i=1;i<=belong[n];i++)sudo(l[i],r[i]); while(q--){ if(read()==1){ int sum,pos,lpos; sum=0,pos=lpos=read(); while(pos<=n)sum+=cos[pos],lpos=last[pos],pos=out[pos]; printf("%d %d\n",lpos,sum); }else{ int pos=read(); a[pos]=read(); sudo(l[belong[pos]],r[belong[pos]]); } } } } signed main(){ star::work(); return 0; }
|