Submission #217045

#TimeUsernameProblemLanguageResultExecution timeMemory
217045sevlllStrange Device (APIO19_strange_device)C++17
35 / 100
947 ms81852 KiB
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <queue> #include <bitset> #define pb push_back #define int long long #define int2 __int128_t #define str string using namespace std; const int M = 1e9 + 7; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, a, b; cin >> n >> a >> b; vector<pair<int, int>> pr(n); for (int i = 0; i < n; i++) cin >> pr[i].first >> pr[i].second; int2 g = gcd(a, b + 1); a /= g; int2 num = a * b; vector<pair<int2, int2>> ev; for (auto p : pr) { int2 l = p.first, r = p.second; if (r - l >= num - 1) { cout << (int) num; return 0; } l %= num; r %= num; if (r < l) { ev.pb({l, 1}); ev.pb({num, -1}); ev.pb({0, 1}); ev.pb({r + 1, -1}); } else { ev.pb({l, 1}); ev.pb({r + 1, -1}); } } sort(ev.begin(), ev.end()); int2 bal = 0; int2 last = 0; int ans = 0; for (auto p : ev) { int2 x = p.first; int2 type = p.second; if (bal) { ans += (x - last); } last = x; bal += type; } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...