Submission #543521

#TimeUsernameProblemLanguageResultExecution timeMemory
543521OttoTheDinoStrange Device (APIO19_strange_device)C++17
100 / 100
1680 ms100144 KiB
#include <bits/stdc++.h> using namespace std; int main(){ long long n, a, b, ans=0; cin>>n>>a>>b; if (log(a)+log(b)>log(__gcd(a,b+1))+log(1e18)){ for (int i =0; i<n; ++i){ long long li,ri;cin>>li>>ri; ans += ri-li+1; } cout<<ans<<endl; return 0; } long long s = a/__gcd(a,b+1)*b; set<pair<long long, long long>> st; for (int i = 0; i<n;++i){ long long li, ri; cin >> li >> ri; if (ri-li>=s) st.insert({0,s-1}); else if (ri%s<li%s){ st.insert({0,ri%s}); st.insert({li%s,s-1}); } else st.insert({li%s,ri%s}); } ans =s; long long x = -1; for (auto el : st) { ans -= max (el.first-x-1, 0LL); x = max (x, el.second); } ans -= s-1-x; cout << ans << endl; 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...