Description
One day, Lostmonkey invented a super-elastic device, in order to show off in front of his sheep friends, he invited the little sheep to play a game. At the beginning of the game, Lostmonkey on the ground along a straight line to put n devices, each device set the initial elastic coefficient ki, when the sheep reached the first device, it will bounce Ki step back to the first I+ki device, if there is no i+ki device, then the sheep were bounced. The sheep wanted to know that when it started from the device I, it was bounced a few times. In order to make the game more interesting, Lostmonkey can modify the elastic coefficient of an elastic device, and the elastic coefficient is a positive integer at any time.
Input
The first line contains an integer n, which indicates that there are n devices on the ground, the device is numbered from 0 to N-1, and the next line has n positive integers, followed by the initial elastic coefficients of the n units. The third line has a positive integer m, the next m row each line has at least two number I, J, if I=1, you want to output from J is bounced several times after being bounced, if i=2 will also enter a positive integer k, indicating that the coefficient of the J-Elastic device is modified to K. For data n,m<=10000 of 20%, for 100% of data n<=200000,m<=100000
Output
For each i=1, you will output a required number of steps, one row.
Sample Input4
1 2 1 1
3
1 1
2 1 1
1 1
Sample Output
2
3
The puzzle tells us to use Splay's heuristic merge or dynamic tree to write, however I will not, later come back to pits. This problem naturally uses a block of violence.
Records the number of steps that each node takes to jump out of the block and jumps to the next one.
1#include <cstdio>2#include <cmath>3 #definell Long Long4 Const intmaxn=200010;5 structaa{intNum,next,bs,block;} A[MAXN];//next is to jump to which of the next piece, BS is the number of steps, backward to find, block for that piece6 intmid,opt,w,shu,n,cnt;7 intFindintW) {8 intans=0;9 while(w<=N) {Tenans+=a[w].bs; Onew=A[w].next; A } - returnans; - } the - voidChangeintWintnum) { -a[w].num=num; - for(intI=a[w].block*mid;i> (a[w].block-1) *mid;i--){ + if(A[i].num+i>a[i].block*mid) a[i].bs=1, a[i].next=i+A[i].num; - ElseA[i].bs= (a[a[i].num+i].bs+1), a[i].next=a[a[i].num+I].next; + } A } at inline ll read () - { -ll x=0, f=1;CharCh=GetChar (); - while(ch>'9'|| ch<'0'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} - returnx*F; in } - intMain () { to inttot=0, M; +scanf"%d",&n); -Mid= (int) sqrt (n) +1; the for(intI=1; i<=n;i++) a[i].num=read (); * for(intI=1; i<=n;i++){ $ if(I>tot*mid) tot++;Panax Notoginsenga[i].block=tot; - } the for(intI=n;i>0; i--) { + if(A[i].num+i>a[i].block*mid) a[i].bs=1, a[i].next=i+A[i].num; A Else if(a[i].num+i>n) a[i].bs=1, a[i].next=n+1;//This must be the last one, or WA. the ElseA[i].bs= (a[a[i].num+i].bs+1), a[i].next=a[a[i].num+I].next; + } -scanf"%d",&m); $ for(intj=0; j<m;j++){ $scanf"%d",&opt); - if(cnt==322){ - the - }Wuyi Switch(opt) { the Case 1: W=read (); cnt++;p rintf ("%d\n", Find (w+1)); Break; - Case 2: W=read (), Shu=read (); Change (w+1, Shu); Break; Wu } - } About}
Bzoj 2002[hnoi2010]bounce Flying Sheep