This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ins insert
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
int nxt(){ int x;cin>>x; return x; }
const int mod = 1e9 +7, sze = 2e5 +10, inf = LLONG_MAX, LG = 20;
const int B= 555;
int pref[B][B];
int event[sze][B],dp[sze];
void nev(int pos,int jump,int val){
if(pos>=sze){
return;
}
val=(val + mod)%mod;
event[pos][jump]=(event[pos][jump] +val)%mod;
}
void rush(){
int n;
cin>>n;
vector<pair<int,int>> arr(n+1);
for(int i=1;i<=n;i++){
cin>>arr[i].first>>arr[i].second;
}
dp[1]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<B;j++){
pref[ i%j ][j] = ( pref[i%j][j] + event[i][j] + mod)%mod;
dp[i]=(dp[i] + pref[i%j][j] + mod)%mod;
}
if( arr[i].first){
if(arr[i].first >= B){
for(int j = arr[i].first + i, c = 1;c<=arr[i].second, j<=n; j+=arr[i].first, c++){
dp[j]= (dp[j] + dp[i] + mod)%mod;
}
}
else{
nev(i + arr[i].first, arr[i].first, dp[i]);
nev( i + arr[i].first * (1+arr[i].second), arr[i].first, -dp[i]);
}
}
}
int ans=0;
for(int i=1;i<=n;i++){
ans=(ans+dp[i])%mod;
}
putr(ans);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
// cin>>tt;
while(tt--){
rush();
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void rush()':
Main.cpp:40:54: warning: value computed is not used [-Wunused-value]
40 | for(int j = arr[i].first + i, c = 1;c<=arr[i].second, j<=n; j+=arr[i].first, c++){
| ~^~~~~~~~~~~~~~~
# | 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... |