#x1038. CF797E Array Queries

CF797E Array Queries

Array Queries

题面翻译

  • 给定长度为 nn 的序列 aaqq 次询问。
  • 每次询问给出 p,kp,k。您要不断地执行操作 pp+ap+kp\gets p+a_p+k,直到 p>np>n 为止。询问的答案为操作次数。
  • 1n,q1051\le n,q\le 10^51ain1\le a_i\le n1p,kn1\le p,k\le n

题目描述

a a is an array of n n positive integers, all of which are not greater than n n .

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

输入格式

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

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

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

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

输出格式

Print q q integers, i i th integer must be equal to the answer to i i th query.

样例 #1

样例输入 #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=3 p=3 , after second operation p=5 p=5 .

In next two queries p p is greater than n n after the first operation.