제출 #993202

#제출 시각아이디문제언어결과실행 시간메모리
993202vladiliusTrains (BOI24_trains)C++17
100 / 100
158 ms4996 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...