#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int main(){
int n;
while (cin >> n){
vector<int> elem(n + 1);
for (int i = 1; i <= n; i++) cin >> elem[i];
int dp[100002][410];
for (int i = n; i >= 1; i--){
for (int j = 0; j < 410; j++){
if (i + elem[i] + j>n) dp[i][j] = 1;
else dp[i][j] = dp[i + elem[i] + j][j] + 1;
}
}
int q;
cin >> q;
while (q){
int p, k;
cin >> p >> k;
if (k < 410) cout << dp[p][k] << endl;
else{
int amount = 0;
while (p <= n){
p = p + elem[p] + k;
amount++;
}
cout << amount << endl;
}
q--;
}
}
return 0;
}
797E - Array Queries
最新推荐文章于 2022-07-12 20:42:11 发布