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;
const int nx=1e5+5, mod=1e9+7, kx=255;
int n, d[nx], x[nx], qs[kx][kx], dp[nx], res, k=250;
vector<int> rem[nx];
void add(int idx)
{
if (d[idx]==0||x[idx]==0) return;
if (d[idx]>k)
{
for (int i=idx+d[idx], j=0; j<x[idx]&&i<=n; j++, i+=d[idx]) dp[i]=(dp[i]+dp[idx])%mod;
}
else
{
qs[d[idx]][idx%d[idx]]=(qs[d[idx]][idx%d[idx]]+dp[idx])%mod;
if (idx+((long long)x[idx])*d[idx]<=n) rem[idx+((long long)x[idx])*d[idx]].push_back(idx);
}
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>d[i]>>x[i];
dp[1]=1;
add(1);
for (int i=2; i<=n; i++)
{
for (int j=1; j<=k; j++) dp[i]=(dp[i]+qs[j][i%j])%mod;
add(i);
for (auto idx:rem[i]) qs[d[idx]][i%d[idx]]=((qs[d[idx]][i%d[idx]]-dp[idx])%mod+mod)%mod;
}
for (int i=1; i<=n; i++) res=(res+dp[i])%mod;
cout<<res;
}
# | 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... |