题目链接

题意:给以 一个数组,给你一些询问,每次询问给出 p , k p,k p,k,可以执行一些操作,每次操作会使得
p > p + a p + k p->p+a_p+k p>p+ap+k,直到p大于n,问最大操作数。
思路:我们知道因为每次都会加至少k次,(假设数组全为0),然后我们根据k的大小分块计算
先把 k n k\leq \sqrt{n} kn 的部分dp计算出来,然后询问到的时候直接 O ( 1 ) O(1) O(1)回答, k > n k>\sqrt{n} k>n 的部分直接暴力模拟一边即可,因为最大只会跳不超过 n \sqrt{n} n 次。

细节见代码:

#include<bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define LL long long
#define SZ(X) X.size()
#define pii pair<int,int>
#define ALL(X) X.begin(),X.end()
 
using namespace std;
 
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
LL lcm(LL a, LL b) {return a / gcd(a, b) * b;}
LL powmod(LL a, LL b, LL MOD) {LL ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
const int N = 1e5 + 11;
int n,q,a[N],k;
struct uzi{
    int l,r;
};
int f[320][N];
void gao(){
    cin>>q;
    for(int i=1;i<=q;i++){
        int l,r;
        cin>>l>>r;
        if(1ll*r*r<=n)cout<<f[r][l]<<endl;
        else{
            int cnt=0;
            while(l<=n){
                cnt++;
                l=l+r+a[l];
            }
            cout<<cnt<<endl;
        }
    }
}
int main() {
	ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=n;i>=1;i--){
        for(int j=1;j*j<=n;j++){
            f[j][i]=(((a[i]+j+i)<=n)?f[j][a[i]+j+i]:0)+1;
        }
    }
    gao();
	return 0;
}