VIJOSP1471 's Playground
Links: https://vijos.org/p/1471
Ideas
Recursion.
First find the leftmost one can jump to the rear of the L,
Then the points after the L have two cases: either a enough to jump to the rear steps of 1, or can be a pace to l have L jump to the rear of the number of steps to 2.
For points prior to L, the same operation would be equivalent to reducing R to L in the code.
Code
1#include <iostream>2#include <cstdio>3 using namespacestd;4 5 Const intMAXN =100000+Ten;6 7 intn,q;8 intA[MAXN],STEP[MAXN];9 TenInlineintRead_int () { One CharC=GetChar (); A while(!isdigit (c)) c=GetChar (); - intx=0; - while(IsDigit (c)) { thex=x*Ten+c-'0'; -C=GetChar (); - } - returnx; + } - + intMain () { AIos::sync_with_stdio (false); atN=read_int (); q=read_int (); - for(intI=1; i<=n;i++) a[i]=read_int (); - - intL=1, r=n+1; -step[r]=0; - Do{ in intI=1; - while(I+a[i]<r) i++; to for(intj=i;j<r;j++) + if(j+a[j]>=r) step[j]=step[r]+1; - Elsestep[j]=step[r]+2; theR=i; *} while(r>1); $ intx;Panax Notoginseng for(intI=1; i<=q;i++) { -x=read_int (); thecout<<Step[x]; + if(I<Q) cout<<" "; A Else thecout<<"\ n"; + } - return 0; $}
VIJOSP1471 's Playground