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;
long long inf=1e18+10;
long long mul(long long a,long long b){
if(inf/a<b){
return inf;
}
else{
long long ret=1ll*a*b;
return ret;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
long long a,b;
cin>>n>>a>>b;
long long e=mul(a/gcd(a,(b+1)),b);
map<long long ,long long>mp;
for(int i=0;i<n;i++){
long long l,r;
cin>>l>>r;
if(r-l+1>=e){
cout<<e<<"\n";
return 0;
}
l%=e;
r%=e;
// cout<<l<<" "<<r<<endl;
mp[l]++;
if(l>r){
mp[e]--;
mp[0]++;
}
mp[r+1]--;
}
long long last=0;
for(auto x:mp){
mp[x.first]+=last;
last=mp[x.first];
}
long long res=0;
long long ll=0,rr=0,f=0;
for(auto x:mp){
rr=x.first;
if(x.second==0){
// cout<<rr<<" "<<ll<<" "<<x.first<<endl;
res+=rr-ll;
ll=rr;
f=0;
}
else{
if(f==0){
ll=x.first;
f=1;
}
}
}
cout<<res<<endl;
}
# | 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... |