Submission #1019381

#TimeUsernameProblemLanguageResultExecution timeMemory
1019381avighnaStrange Device (APIO19_strange_device)C++17
0 / 100
5041 ms524288 KiB
#include <bits/stdc++.h> typedef long long ll; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); ll n, a, b; std::cin >> n >> a >> b; if (b == 1) { // (2x % a, 0) // 2x % a == 0 // if a is odd, then the cycle is of length a (the 2 will never contribute) // if a is even, then the cycle of of length a/2 ll cycle = a % 2 == 0 ? a / 2 : a; std::vector<std::pair<ll, ll>> ranges; std::map<ll, ll> mp; while (n--) { ll l, r; std::cin >> l >> r; ll _l = l % cycle, _r = r % cycle; if (r - l + 1 >= cycle) { std::cout << cycle << "\n"; return 0; } if (_l > _r) { ranges.push_back({_l, cycle - 1}); ranges.push_back({0, _r}); } else { ranges.push_back({_l, _r}); } } for (auto &[l, r] : ranges) { mp[l] = std::max(mp[l], r); } ll right = 0; ll ans = 0; for (auto &i : mp) { if (i.second < right) { continue; } ans += i.second - right + 1; right = i.second; } std::cout << ans << "\n"; return 0; } std::set<std::pair<ll, ll>> st; while (n--) { ll l, r; std::cin >> l >> r; for (ll x = l; x <= r; ++x) { st.insert({(x + x / b) % a, x % b}); } } std::cout << st.size() << "\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...