Submission #654686

#TimeUsernameProblemLanguageResultExecution timeMemory
654686horiseunStrange Device (APIO19_strange_device)C++11
35 / 100
644 ms87908 KiB
#include <iostream> #include <vector> #include <set> #include <tuple> #include <algorithm> using namespace std; #define ll long long #define f first #define s second ll a, b, n, l, r, p, ans, c, lft; vector<pair<ll, bool>> v; ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> a >> b; p = b * (a / gcd(a, b + 1)); for (int i = 0; i < n; i++) { cin >> l >> r; if (r - l >= p) { cout << p << "\n"; return 0; } if ((l + p - 1) % p > (r + p - 1) % p) { v.push_back({1, 0}); v.push_back({(l + p - 1) % p + 1, 0}); v.push_back({(r + p - 1) % p + 1, 1}); v.push_back({p, 1}); } else { v.push_back({(l + p - 1) % p + 1, 0}); v.push_back({(r + p - 1) % p + 1, 1}); } } sort(v.begin(), v.end()); lft = -1; for (pair<ll, bool> i : v) { if (!i.s) { c++; if (lft == -1) lft = i.f; } else { c--; if (c == 0) { ans += (i.f - lft + 1); lft = -1; } } } cout << ans << "\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...