This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define cd complex<double>
#define ld long double
#define all(x) (x).begin(), (x).end()
#define iii tuple<int, int, int>
const ll mod = 1e9 + 7;
const ll INF = 1e18L + 5;
const double PI = acos(-1);
const int block = 320;
const int N = 1e5;
int tc, tt = 1;
int n;
ll d[N + 5], x[N + 5];
namespace sub1 {
bool ck() {
return n <= 15;
}
ll dp[N + 5];
void sol() {
dp[1] = 1;
for(int i=1; i<=n; i++) if(d[i] != 0) {
for(int j=i + d[i]; j<=min(1LL*n, i + x[i] * d[i]); j+=d[i])
dp[j] = (dp[j] + dp[i]) % mod;
}
ll ans = 0;
for(int i=1; i<=n; i++) ans = (ans + dp[i]) % mod;
cout<<ans;
}
}
namespace sub2 {
bool ck() {
return true;
}
struct node {
ll i, j, d;
};
ll dp[N + 5], sum[block + 100][block + 100];
vector<node> end[N + 5];
void sol() {
memset(sum, 0, sizeof(sum));
dp[1] = 1;
for(int i=1; i<=n; i++) {
for(int j=1; j<=block; j++)
dp[i] = (dp[i] + sum[j][i % j]) % mod;
for(auto x: end[i])
sum[x.i][x.j] = (sum[x.i][x.j] + mod - x.d) % mod;
if(d[i] == 0) continue;
if(d[i] > block) {
for(int j=i + d[i]; j<=min(1LL * n, i + x[i] * d[i]); j+=d[i])
dp[j] = (dp[j] + dp[i]) % mod;
}
else {
if(x[i] == 0) continue;
if(i + x[i] * d[i] <= n)
end[i + x[i] * d[i]].pb({d[i], i % d[i], dp[i]});
sum[d[i]][i % d[i]] = (sum[d[i]][i % d[i]] + dp[i]) % mod;
}
}
ll ans = 0;
for(int i=1; i<=n; i++) ans = (ans + dp[i]) % mod;
cout<<ans;
}
}
void solve() {
cin>>n;
for(int i=1; i<=n; i++) cin>>d[i]>>x[i];
if(sub1::ck()) {sub1::sol(); return;}
if(sub2::ck()) {sub2::sol(); return;}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
for(tc=1; tc<=tt; tc++) solve();
cerr<<"\nTime elapsed: "<<1000.0*clock()/CLOCKS_PER_SEC<<" ms.\n";
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... |