#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ed "\n"
#define fi first
#define se second
#define db double
#define irs insert
#define pb push_back
#define mpa make_pair
#define pi pair<int,int>
#define MASK(i) (1LL << (i))
#define BIT(x, i) ((x>>i)&1)
#define ON(x, i) ((x) MASK(i))
#define OFF(x, i) ((x) & ~MASK(i))
#define ALL(v) v.begin() , v.end()
#define bp(x) __builtin_popcount(x)
#define pii pair<int,pair<int,int>>
#define fl(i,a,b) for(int i=a;i>=b;--i)
#define fis(i,a,b) for(int i=a;i<=b;++i)
#define Radian(x) (x * acos(-1.0) / 180)
const double eps = 1e-9;
const int mod=1e9+7;
const int Mdem=998244353;
const int LOG=19;
const int base=31;
const int maxn=2e5+5;
const int bl = 320;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gay(a) freopen(a".inp","r",stdin),freopen(a".out","w",stdout)
template <class T>
bool minimize(T &a, const T &b) {
if(a > b) {a = b; return 1;}
return 0;
}
template <class T>
bool maximize(T &a, const T &b) {
if(a < b) {a = b; return 1;}
return 0;
}
template <class T>
void compress(vector <T> &v) {
sort(ALL(v));
v.erase(unique(ALL(v)), (v).end());
}
void add(int &a, int b) { a += b; if (a >= mod) a -= mod; }
void sub(int &a, int b) { a -= b; if (a < 0) a += mod; }
struct Fenwick{
int n;
vector<int> tree;
Fenwick(int _n = 0){
n = _n;
tree.resize(n + 1);
}
void update(int x, int val){
if(val == -1) val = tree[x];
for(; x <= n; x += x & -x) add(tree[x], val);
}
int get(int x){
int res = 0;
for(; x; x -= x & -x) add(res, tree[x]);
return res;
}
int query(int l, int r){
if(l == 0) return get(r);
if(r == 0) return 0;
else{
int x = get(r); sub(x, get(l - 1));
return x;
}
}
};
int n, dp[maxn], d[maxn], x[maxn];
int sum[325][maxn];
int block = 320;
vector<int> Del[maxn];
signed main(){
fast;
cin >> n;
// Fenwick f = Fenwick(n);
fis(i, 1, n) cin >> d[i] >> x[i];
dp[1] = 1;
fis(i, 1, n){
for(int j : Del[i]) sub(sum[d[j]][j % d[j]], dp[j]);
fis(j, 1, block) add(dp[i], sum[j][i % j]);
if(d[i] > block){
for(int v = 1; v <= x[i] && i + v * d[i] <= n; ++v){
add(dp[i + v * d[i]], dp[i]);
}
}
else{
if(d[i] == 0) continue;
add(sum[d[i]][i % d[i]], dp[i]);
if(i + d[i] * (x[i] + 1) <= n) Del[i + d[i] * (x[i] + 1)].pb(i);
}
}
int ans = 0;
fis(i, 1, n) add(ans, dp[i]);
cout << ans << ed;
// [i + d[i], i + d[i] * x[i]]
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... |