Submission #819968

#TimeUsernameProblemLanguageResultExecution timeMemory
819968AlanStrange Device (APIO19_strange_device)C++17
15 / 100
1548 ms100212 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll inf = 1e18; void add (set<pair<ll, ll>>& st, ll l, ll r) { auto it = st.lower_bound({l, 0}), tmp = it; if (it != st.begin() && (--tmp)->second >= l) { l = tmp->first; st.erase(tmp); } while (it != st.end()) { if (r >= it->first) { r = max(r, it->second); it = st.erase(it); } else break; } st.insert({l, r}); } int main () { ll n, a, b; cin >> n >> a >> b; ll mod; if (a / gcd(a, b+1) > inf / b) mod = inf; else mod = a / gcd(a, b+1) * b; set<pair<ll, ll>> st; while (n--) { ll l, r; cin >> l >> r; if (r-l+1 >= mod) { cout << mod << '\n'; return 0; } if (l % mod > r % mod) { add(st, 0, r % mod); add(st, l % mod, mod-1); } else add(st, l % mod, r % mod); } ll ans = 0; for (auto& [l, r] : st) ans += r-l+1; cout << ans << '\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...