BZOJ2002 (sub-block)

Source: Internet
Author: User

Bounce Fly SheepTime limit:10000MS Memory Limit:265216KB 64bit IO Format:%lld &%ll U SubmitStatusDescription

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 Input
4 1 2 1 1 31 12 1 11 1
Sample Output
23

Chunking
1 //2016.8.122#include <iostream>3#include <cstdio>4#include <cmath>5#include <algorithm>6 7 using namespacestd;8 9 Const intN =200005;Ten intK[n], Step[n], nex[n];//Step[i] record I points step out of the block, Nex[i] record I get out of the block to reach the point One  A intMain () - { -     intN, M, A, B, C, CNT, ans; thescanf"%d", &n); -     { -         intLen = (int) sqrt (n); -          for(inti =0; I < n; i++) +scanf"%d", &k[i]); -          for(inti = n1; I>0; i--) +         { A             intTMP = i+K[i]; at             if(tmp>=N) -             { -Step[i] =1; -Nex[i] =-1;//1 means out of the range . -}Else if(Tmp>= (i/len+1)*len) -Step[i] =1, nex[i] =tmp; in             Else -Nex[i] = nex[tmp], step[i] = step[tmp]+1; to         } +scanf"%d", &m); -          while(m--) the         { *scanf"%d%d", &a, &b); $             if(a==1)Panax Notoginseng             { -Ans =0; the                  for(inti = b; ~i;i = Nex[i])//when I==-1, ~i==0, for false exit +                 { Aans+=Step[i]; the                 } +printf"%d\n", ans); -}Else $             { $scanf"%d", &c); -K[B] =C; -                  for(inti = b; I >= B/len*len; i--) the                 { -                     intTMP = i+K[i];Wuyi                     if(tmp>=N) theStep[i] =1, nex[i] =-1; -                     Else if(Tmp>= (i/len+1)*len) WuStep[i] =1, nex[i] =tmp; -                     Else AboutStep[i] = step[tmp]+1, nex[i] =nex[tmp]; $                 } -             } -         } -     } A  +     return 0; the}

BZOJ2002 (sub-block)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.