이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pli = pair<ll, int>;
const int mod = 1e9 + 7;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<int> d(n + 1), x(n + 1);
for (int i = 1; i <= n; i++){
cin>>d[i]>>x[i];
}
vector<ll> dp(n + 1); dp[1] = 1;
int sq = (int) sqrt(n);
vector<vector<ll>> sum(sq, vector<ll>(sq));
auto recalc = [&](int i){
for (int f = 1; f < sq; f++){
dp[i] = (dp[i] + sum[f][i % f]) % mod;
}
};
priority_queue<pli, vector<pli>, greater<pli>> pq;
auto add = [&](int i){
recalc(i);
if (!d[i]) return;
if (d[i] >= sq){
for (int j = 1; j <= x[i]; j++){
ll v = i + 1LL * d[i] * j;
if (v > n) break;
dp[v] = (dp[v] + dp[i]) % mod;
}
return;
}
pq.push({i + 1LL * d[i] * x[i], i});
sum[d[i]][i % d[i]] += dp[i];
sum[d[i]][i % d[i]] %= mod;
};
for (int i = 1; i <= n; i++){
add(i);
while (!pq.empty()){
auto [v, j] = pq.top();
if (v > i) break;
pq.pop();
sum[d[j]][j % d[j]] -= dp[j];
sum[d[j]][j % d[j]] %= mod;
}
}
ll out = 0;
for (int i = 1; i <= n; i++){
out = (out + dp[i]) % mod;
}
cout<<(out + mod) % mod<<"\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... |