이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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= 623;
int pref[B][B];
int event[sze][B],dp[sze];
void nev(int pos,int jump,int val){
if(pos>=sze){
return;
}
event[pos][jump]=(event[pos][jump] +val + mod)%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++){
int q= i%j;
pref[ q ][j] = ( pref[q][j] + event[i][j] + mod)%mod;
dp[i]=(dp[i] + pref[q][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*arr[i].second + arr[i].first, arr[i].first, -dp[i]);
}
}
}
int ans=0;
for(int i=1;i<=n;i++){
ans=(ans+dp[i] + mod)%mod;
}
ans=(ans+mod)%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;
}
# | 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... |