#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define fi first
#define se second
const int N = 2e5;
const int mod = 1e9+7;
const int INF = 1e9;
const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};
ll t[4*N],modify[4*N];
void push(int v,int l,int r) {
if(modify[v]!=0 and v+v+1<4*N) {
modify[v+v]+=modify[v];
modify[v+v+1]+=modify[v];
modify[v+v]%=mod;
modify[v+v+1]%=mod;
int mid=(l+r)/2;
t[v+v]+=(mid-l+1)*1ll*modify[v];
t[v+v+1]+=(r-mid)*1ll*modify[v];
t[v+v]%=mod;
t[v+v+1]%=mod;
modify[v]=0;
}
}
void upd(int v,int l,int r,int rl,int rr,ll x) {
if(r<rl or rr<l)
return;
if(rl<=l and r<=rr) {
t[v]+=(r-l+1)*x;
modify[v]+=x;
t[v]%=mod;
modify[v]%=mod;
return;
}
push(v,l,r);
int mid=(l+r)/2;
upd(v+v,l,mid,rl,rr,x);
upd(v+v+1,mid+1,r,rl,rr,x);
t[v]=(t[v+v]+t[v+v+1])%mod;
}
int get(int v,int l,int r,int pos){
if(l==r)
return t[v];
else{
push(v,l,r);
int mid=(l+r)/2;
if(pos<=mid)
return get(v+v,l,mid,pos);
else
return get(v+v+1,mid+1,r,pos);
}
}
void solve() {
int n;
cin>>n;
int d[n+1],x[n+1];
bool check=1;
for(int i = 1; i <= n; i++){
cin>>d[i]>>x[i];
if(d[i]!=1)
check=0;
}
if(check){
upd(1,1,n,1,1,1);
for(int i = 1; i <= n; i++){
if(x[i]>0){
ll val=get(1,1,n,i)%mod;
upd(1,1,n,i+1,i+x[i],val);
}
}
ll ans=0;
for(int i = 1; i <= n; i++){
ans=(ans+get(1,1,n,i))%mod;
}
cout<<ans<<"\n";
return;
}
ll dp[n+1];
memset(dp,0,sizeof(dp));
dp[1]=1;
for(int i = 2; i <= n; i++){
for(int j = 1; j < i; j++){
if(d[j]==0)
continue;
int k=(i-j)/d[j];
if(i%d[j]==j%d[j] && 1<=k && k<=x[j]){
dp[i]=(dp[i]+dp[j])%mod;
}
}
}
ll ans=0;
for(int i = 1; i <= n; i++){
ans=(ans+dp[i])%mod;
}
cout<<ans<<"\n";
}
int main() {
//freopen("cowrun.in","r",stdin);
//freopen("cowrun.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
//cin>>t;
while(t--) {
solve();
}
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... |