CF797E.Array Queries

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

aa is an array of nn positive integers, all of which are not greater than nn .

You have to process qq queries to this array. Each query is represented by two numbers pp and kk . Several operations are performed in each query; each operation changes pp to p+ap+kp+a_{p}+k . There operations are applied until pp becomes greater than nn . The answer to the query is the number of performed operations.

输入格式

The first line contains one integer nn (1<=n<=100000)(1<=n<=100000) .

The second line contains nn integers — elements of aa ( 1<=ai<=n1<=a_{i}<=n for each ii from 11 to nn ).

The third line containts one integer qq (1<=q<=100000)(1<=q<=100000) .

Then qq lines follow. Each line contains the values of pp and kk for corresponding query (1<=p,k<=n)(1<=p,k<=n) .

输出格式

Print qq integers, ii th integer must be equal to the answer to ii th query.

输入输出样例

  • 输入#1

    3
    1 1 1
    3
    1 1
    2 1
    3 1
    

    输出#1

    2
    1
    1
    

说明/提示

Consider first example:

In first query after first operation p=3p=3 , after second operation p=5p=5 .

In next two queries pp is greater than nn after the first operation.

首页