Submission #708303

#TimeUsernameProblemLanguageResultExecution timeMemory
708303600MihneaStrange Device (APIO19_strange_device)C++17
100 / 100
732 ms79040 KiB
#include <cmath> #include <functional> #include <fstream> #include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> #include <map> #include <list> #include <time.h> #include <math.h> #include <random> #include <deque> #include <queue> #include <unordered_map> #include <unordered_set> #include <iomanip> #include <cassert> #include <bitset> #include <sstream> #include <chrono> #include <cstring> #include <numeric> #include <cstdint> #include <limits> #include <numeric> #include <iostream> using namespace std; #define int long long int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } signed main() { #ifdef ONPC FILE* stream; freopen_s(&stream, "input.txt", "r", stdin); #else ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif int n, mod; cin >> n; { int a, b; cin >> a >> b; a /= gcd(a, b + 1); if (a <= ((int)1e18 + 7) / b) { a *= b; mod = a; } else { mod = ((int)1e18 + 7); } } map<int, int> mars; auto add = [&](int l, int r) { if (l > r) return; mars[l]++; mars[r + 1]--; }; vector<pair<int, int>> segs(n); for (auto& it : segs) { cin >> it.first >> it.second; if (it.second - it.first + 1 >= mod) { cout << mod << "\n"; exit(0); } int l = it.first % mod, r = it.second % mod; if (l <= r) { add(l, r); } else { add(l, mod - 1); add(0, r); } } int sol = 0, cur = 0, last; for (auto& it : mars) { if (cur) { sol += it.first - last; } last = it.first; cur += it.second; } cout << sol << "\n"; exit(0); return 0; }
#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...