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 MAXN = 1e5+5;
const int MOD = 1e9+7;
const int BLOCK = 300;
typedef long long ll;
int n;
struct mint {
int v;
mint(int v) : v(v) {}
mint() {v=0;}
};
mint operator+(mint a, mint b) {
return a.v + b.v >= MOD ? mint(a.v+b.v-MOD) : mint(a.v+b.v);
}
void operator+=(mint &a, mint b) {
a.v += b.v;
if (a.v >= MOD) a.v -= MOD;
}
void operator-=(mint &a, mint b) {
a.v -= b.v;
if (a.v < 0) a.v += MOD;
}
mint pre[MAXN][BLOCK]; // i, i+j, i+2j, ...
mint dp[MAXN];
int d[MAXN], x[MAXN];
mint sum(int l, ll r, int dist) {
mint ans;
if (l < n) ans += pre[l][dist];
if (r < n) ans -= pre[r][dist];
return ans;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> d[i] >> x[i];
if (d[i] > n) d[i] = n;
if (x[i] > n) x[i] = n;
}
for (int i = n-1; i >= 0; i--) {
dp[i].v = 1;
ll e = (ll)d[i]*(x[i]+1) + i;
// if (e > n) e -= d[i]*((e-n)/d[i]);
if (d[i] < BLOCK) {
dp[i] += sum(i+d[i], e, d[i]);
}
else {
for (int j = i+d[i]; j < e && j < n; j += d[i]) dp[i] += dp[j];
}
for (int j = 1; j < min(BLOCK, n); j++) pre[i][j] = dp[i] + (i+j >= n ? 0 : pre[i+j][j]);
}
cout << dp[0].v << '\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... |