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;
typedef long long ll;
typedef __int128 lll;
int n,curr;
ll a,b,ans,l,r,cc,pre=-1;
lll cyc;
map<ll,int> todo;
int main(){
cin>>n>>a>>b;
cyc=a/__gcd(a,b+1);
cyc*=b;
if (cyc>=LLONG_MAX) cc=LLONG_MAX;
else cc=cyc;
for (int i=1;i<=n;i++){
cin>>l>>r;
if (r-l>=cc){
cout<<cc<<"\n";
return 0;
}
if (l/cc!=r/cc){
todo[l%cc]++;
todo[cc]--;
todo[0]++;
todo[r%cc+1]--;
}else{
todo[l%cc]++;
todo[r%cc+1]--;
}
}
for (auto i:todo){
if (curr) ans+=i.first-pre;
curr+=i.second;
pre=i.first;
}
cout<<ans<<"\n";
}
# | 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... |