이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,fma,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
#define int long long
using namespace std;
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=1e5,MOD=1e9+7;
int n,x[N+5],d[N+5],m[320][320],dp[N+5];
map <pair<int,int>,int> mp[N+5];
vector <pair<int,int>> v[N+5];
void Solve(){
cin>>n;
int block=sqrt(n);
for (int i=1;i<=n;++i){
cin>>d[i]>>x[i];
int o=i+d[i]*x[i];
if (o+d[i]<=n) v[o].push_back({d[i],x[i]});
}
for (int i=n;i>=1;--i){
dp[i]=1;
if (!d[i] || !x[i]) dp[i]=1;
else if (d[i]>block){
int j=i+d[i];
while (j<=n){
dp[i]+=dp[j];
j+=d[i];
}
dp[i]%=MOD;
}
else dp[i]=m[d[i]][i%d[i]]+1;
for (pair <int,int> p : v[i]){
int d=p.first,x=p.second;
if (!d || !x) mp[i][p]=0;
else if (d>block){
int j=i+d,val=0;
while (j<=n){
val+=dp[j];
j+=d;
}
val%=MOD;
mp[i][p]=val;
}
else mp[i][p]=m[d][i%d];
}
if (d[i] && x[i]){
int o=i+d[i]*x[i];
if (o+d[i]<=n) dp[i]-=mp[o][{d[i],x[i]}];
dp[i]=(dp[i]%MOD+MOD)%MOD;
}
for (int j=1;j<=block;++j) m[j][i%j]=(m[j][i%j]+dp[i])%MOD;
}
cout<<dp[1];
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen ("FILE.INP","r",stdin);
// freopen ("FILE.OUT","w",stdout);
int t=1;
while (t--) Solve();
cerr<<"\nTIME: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
}
# | 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... |