#include <bits/stdc++.h>
using namespace std;
#define int long long
const int m = 1e9 + 7;
int n, dp[100005];
pair<int, int> a[100005];
vector<int> v;
unordered_map<int, int> tmp;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
unordered_map<int, int> rem[100005];
int32_t main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
dp[1] = 1;
for (int i = 1; i <= n; i++) {
if (a[i].first == 0) continue;
if (tmp.find(a[i].first) == tmp.end()) {
tmp[a[i].first] = v.size();
v.push_back(a[i].first);
}
}
if (a[1].first == 0 || a[1].second == 0) {
cout << 0;
return 0;
}
rem[0][1 % a[1].first] = 1;
pq.emplace(a[1].second * a[1].first + 1, 1);
for (int i = 2; i <= n; i++) {
while (!pq.empty() && pq.top().first < i) {
int idx = pq.top().second;
int k = tmp[a[idx].first];
int r = idx % a[idx].first;
rem[k][r] = (rem[k][r] - dp[idx] + m) % m;
pq.pop();
}
for (size_t j = 0; j < v.size(); j++) {
int r = i % v[j];
dp[i] = (dp[i] + rem[j][r]) % m;
}
if (a[i].first > 0) {
int idx = tmp[a[i].first];
int r = i % a[i].first;
rem[idx][r] = (rem[idx][r] + dp[i]) % m;
pq.emplace(a[i].second * a[i].first + i, i);
}
}
int ans = 0;
for (int i = 1; i <= n; i++) ans = (ans + dp[i]) % m;
cout << ans;
}
# | 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... |