Submission #788206

#TimeUsernameProblemLanguageResultExecution timeMemory
788206tvladm2009Strange Device (APIO19_strange_device)C++17
0 / 100
24 ms364 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = (ll) 1e18; int n, a, b; signed main() { ios::sync_with_stdio(0); cin.tie(0); // freopen("input", stdin, "r"); cin >> n >> a >> b; ll period = a / __gcd(b + 1, a); if (INF / period < b) { period = INF; } else { period *= b; } map<ll, int> jmen; function<void(ll, ll)> add = [&](int l, int r) { if (r - l + 1 >= period) { jmen[0]++; } else { l %= period; r %= period; if (l <= r) { jmen[l]++; jmen[r + 1]--; } else { jmen[l]++; jmen[period]--; jmen[0]++; jmen[r + 1]--; } } }; for (int i = 1; i <= n; i++) { int l, r; cin >> l >> r; add(l, r); } jmen[period] = 0; ll sol = 0; int s = 0; ll last = 0; for (auto &i : jmen) { if (s > 0) { sol += i.first - last; } s += i.second; last = i.first; } cout << sol << "\n"; 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...