显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int maxm = 405;
int f[maxn][maxm],a[maxn],n;
int main() {
freopen("arrayque.in","r",stdin);
freopen("arrayque.out","w",stdout);
scanf("%d",&n);
for(int i = 1;i <= n;++ i)scanf("%d",&a[i]);
for(int k = 1;k < maxm;++ k) {
for(int i = n;i;-- i) {
if(i + a[i] + k > n)f[i][k] = 1;
else f[i][k] = f[i + a[i] + k][k] + 1;
}
}
int p,k,Q;
scanf("%d",&Q);
while(Q --) {
scanf("%d%d",&p,&k);
if(k >= maxm) {
int ans = 0;
for(;p <= n;p += a[p] + k)++ ans;
printf("%d\n",ans);
}
else printf("%d\n",f[p][k]);
}
return 0;
}