#include <bits/stdc++.h>
using namespace std;
#define taskname "ko"
const int LIM = 2e5 + 5;
const int MOD = 1e9 + 7;
const int S = 300;
void add(int &x, const int y){
    x+= y;
    if(x >= MOD) x-= MOD;
}
void sub(int &x, const int y){
    x-= y;
    if(x < 0) x+= MOD;
}
int n;
int d[LIM], x[LIM];
int sum[S + 5][LIM], dp[LIM];
vector <int> del[LIM];
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
   // freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout);
    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 &id : del[i]){
            sub(sum[d[id]][id % d[id]], dp[id]);
        }
        for(int j = 1; j <= 300; j++){
            add(dp[i], sum[j][i % j]);
        }
        if(d[i] == 0) continue;
        if(d[i] > 300){
            for(int j = 1; j <= x[i]; j++){
                if(i + 1LL * j * d[i] > n) break;
                add(dp[i + j * d[i]], dp[i]);
            }
        } else{
            add(sum[d[i]][i % d[i]], dp[i]);
            if (i + 1LL * d[i] * (x[i] + 1) <= n) {
                del[i + d[i] * (x[i] + 1)].push_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... |