#include <bits/stdc++.h>
using namespace std;
#define rep(a, b) for (int a = 0; a < (b); a++)
#define rep1(a, b) for (int a = 1; a <= (b); a++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
#define LOCAL false
const int LIM = 1e5 + 7;
const int SQRT = 320;
int n;
pll dataa[LIM];
ll dp[LIM];
ll total[SQRT+7][SQRT+7]; // total[mod][rem]
ll suff[LIM][SQRT+7]; // suff[idx][step]
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
if (LOCAL) {
ignore=freopen("io/in", "r", stdin);
ignore=freopen("io/out", "w", stdout);
}
cin >> n;
rep(i, n) cin >> dataa[i].first >> dataa[i].second;
fill(dp, dp+n, 1);
for (int i = n-1; i >= 0; i--) {
auto [step, cnt] = dataa[i];
ll endidx = i+step*(cnt+1LL);
if (step != 0) {
if (step > SQRT) for (int s = 1; s <= cnt && i+step*s < n; s++) dp[i] = (dp[i]+dp[i+step*s])%MOD;
else dp[i] = (dp[i]+total[step][i%step]+MOD-(endidx < n ? suff[endidx][step] : 0))%MOD;
}
rep1(m, SQRT) total[m][i%m] = (total[m][i%m]+dp[i])%MOD;
rep1(st, SQRT) suff[i][st] = (dp[i]+(i+st < n ? suff[i+st][st] : 0))%MOD;
}
cout << dp[0] << "\n";
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... |