제출 #1123519

#제출 시각아이디문제언어결과실행 시간메모리
1123519PwoTrains (BOI24_trains)C++17
58 / 100
2127 ms684388 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; typedef long long ll; #define int long long const int m = 1e9 + 7; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") struct chash { const uint64_t C = ll(4e18 * acos(0)) | 71; ll operator()(ll x) const { return __builtin_bswap64(x*C); } }; int n, dp[100005]; pair<int, int> a[100005]; vector<int> v; __gnu_pbds::gp_hash_table<int, int, chash> tmp; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; __gnu_pbds::gp_hash_table<int, int, chash> 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; if (a[1].first == 0 || a[1].second == 0) { cout << 1; return 0; } int ans = 1; tmp[a[1].first] = 0; v.push_back(a[1].first); 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 && a[i].second > 0) { if (tmp.find(a[i].first) == tmp.end()) { tmp[a[i].first] = v.size(); v.push_back(a[i].first); } 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); } ans = (dp[i] + ans) % m; } cout << ans; }
#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...