#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define bitcount __builtin_popcountll
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MOD = 1e9+7;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n; cin>>n;
int SQRT = 0;
while ((SQRT + 1)*(SQRT + 1) < n) SQRT++;
int jump[n], lim[n];
for (int i = 0; i < n; cin>> jump[i] >> lim[i++]);
int dp[n]{}, suff[SQRT][n];
for (int i = n-1; i >= 0; i--) {
if (jump[i] < SQRT) {
long long d = jump[i], x = lim[i];
dp[i] = i + d < n ? suff[d][i + d] : 0;
if (i + d*(x+1) < n) dp[i] -= suff[d][i + d*(x+1)];
if (dp[i] < 0) dp[i] += MOD;
} else {
for (int j = 1; j <= lim[i] && i + jump[i]*j < n; j++) {
dp[i] += dp[i + j*jump[j]];
if (dp[i] >= MOD) dp[i] -= MOD;
}
}
dp[i] = (dp[i] + 1) % MOD;
for (int j = 1; j < SQRT; j++) {
suff[j][i] = dp[i];
if (i + j < n) suff[j][i] += suff[j][i + j];
if (suff[j][i] >= MOD) suff[j][i] -= MOD;
}
}
cout<<dp[0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |