VIJOSP1471 's Playground

Source: Internet
Author: User

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&LT;Q) cout<<" "; A         Else  thecout<<"\ n"; +     } -     return 0; $}

VIJOSP1471 's Playground

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.