#include <bits/stdc++.h>
#define int int64_t
using namespace std;
const int N = 100005;
const int MOD = 1e9 + 7;
const int B = 300;
void add(int &X, int Y) {
if ((X += Y) >= MOD) X -= MOD;
}
int n, d[N], x[N];
int dp[N], tot[B + 5][B];
vector<int> del[N];
signed main(void) {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> d[i] >> x[i];
}
dp[1] = 1;
for (int i = 1; i <= n; i++) {
for (int j: del[i]) {
int &T = tot[d[j]][i % d[j]];
T -= dp[j];
if (T < 0) T += MOD;
}
for (int d = 1; d <= B; d++) {
add(dp[i], tot[d][i % d]);
}
if (d[i] > B) {
for (int k = 1; k <= x[i]; k++) {
if (i + k * d[i] > n) break;
add(dp[i + k * d[i]], dp[i]);
}
} else if (d[i]) {
tot[d[i]][i % d[i]] += dp[i];
int r = i + min(x[i] + 1, n / d[i] + 2) * d[i];
if (r <= n) {
del[r].emplace_back(i);
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) add(ans, dp[i]);
cout << ans;
return 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... |