# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
216992 | 2020-03-28T16:34:16 Z | sevlll | Strange Device (APIO19_strange_device) | C++14 | 0 ms | 0 KB |
#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 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; int g = gcd(a, b+1); a /= g; if (a * b >= 1e18+8800) { int ans = 0; for (auto p : pr) { ans += p.second - p.first+1; } cout << ans; return 0; } int ans = 0; set<int> ses; for (auto p : pr) { int l = p.first, r = p.second; if (l == r) { ses.insert(l%(a*b)); } else { l %= (a * b); r %= (a * b); if (r <= l) r += a * b; for (int x = l; x <= r; x++) { ses.insert(x % (a * b)); } } } cout << ses.size(); }