This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |