#SRD0000012. Truy vấn nhảy trên mảng (Array Queries)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Truy vấn nhảy trên mảng (Array Queries)
Array Queries
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of positive integers, with every , each query specifies two integers . Repeatedly perform
while . Each application counts as one operation, including the operation that makes . Stop once .
For each query, output the number of operations. Queries are independent: the array is never modified and the starting value of is specific to that query. All visited indices strictly increase because and are positive.
Input
The first line contains ; the second contains integers . The third line contains . Each of the following lines contains p k.
Output
For each query, print the number of transformations required for to exceed , one result per line.
Subtasks
- Subtask 1 (10 points): ; ; ; .
- Subtask 2 (20 points): ; ; ; .
- Subtask 3 (30 points): ; ; ; .
- Subtask 4 (40 points): ; ; ; .
Examples
Input
3
1 1 1
3
1 1
2 1
3 1
Output
2
1
1
Explanation
Query (1,1) goes from to , then to , for operations. Query (2,1) reaches immediately; query (3,1) reaches immediately.