Submission #409666

#TimeUsernameProblemLanguageResultExecution timeMemory
409666glebustimStrange Device (APIO19_strange_device)C++17
100 / 100
930 ms98048 KiB
#include <bits/stdc++.h> typedef long long ll; typedef __int128 lll; using namespace std; lll gcd(lll x, lll y) { while (y > 0) { lll z = x % y; x = y; y = z; } return x; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; ll _a, _b; cin >> n >> _a >> _b; lll a = _a, b = _b, len = a * b / gcd(a, b + 1); map<lll, int> s; for (int i = 0; i < n; ++i) { ll l, r; cin >> l >> r; lll f = l % len; if (f + r - l >= len) { ++s[0]; --s[r % len + 1]; ++s[f]; --s[len]; } else { ++s[f]; --s[f + r - l + 1]; } } int bal = 0; ll ans = 0; lll prev = -1; for (auto [t, e]: s) { if (bal > 0) ans += t - prev; bal += e; prev = t; } cout << ans << endl; }
#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...