# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1095794 | 2024-10-03T07:38:13 Z | LucaLucaM | Strange Device (APIO19_strange_device) | C++17 | 3 ms | 1492 KB |
#include <iostream> #include <vector> #include <algorithm> #include <cassert> using ll = long long; using i128 = __int128; int main() { freopen("input.txt", "r", stdin); int n; ll A, B; std::cin >> n >> A >> B; if ((i128) A * B / std::__gcd(A, B + 1) > 1e18) { ll answer = 0; for (int i = 0; i < n; i++) { ll l, r; std::cin >> l >> r; answer += r - l + 1; } std::cout << answer; return 0; } ll R = (i128) A * B / std::__gcd(A, B + 1); std::vector<std::pair<ll, int>> events; bool coverAll = false; for (int i = 0; i < n; i++) { ll l, r; std::cin >> l >> r; if (r - l + 1 >= R) { coverAll = true; } l %= R; r %= R; if (l <= r) { events.push_back({l, +1}); events.push_back({r + 1, -1}); } else { events.push_back({0, +1}); events.push_back({r + 1, -1}); events.push_back({l, +1}); events.push_back({R, -1}); } } if (coverAll) { std::cout << R; return 0; } events.push_back({R, 0}); std::sort(events.begin(), events.end()); i128 last = 0; int delta = 0; ll answer = 0; for (const auto &[pos, add] : events) { if (delta >= 1) { answer += pos - last; } delta += add; last = pos; } std::cout << answer; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |