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 lint;
const lint LNF = 2e18;
int n;
lint A, B;
lint gcd(lint a, lint b){ return (b==0 ? a : gcd(b, a%b)); }
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>A>>B;
lint g = gcd(A, B+1), a=A/g;
lint T = LNF;
if(a<=LNF/B) T = a*B;
map<lint, int> mp;
for(int i=1; i<=n; i++){
lint l,r; cin>>l>>r;
if(r-l+1>=T) mp[0]++, mp[T]--;
else{
l%=T, r%=T;
if(l<=r) mp[l]++, mp[r+1]--;
else mp[0]++, mp[r+1]--, mp[l]++, mp[T]--;
}
}
mp[T] = 0;
lint xp = 0, cnt = 0, ans = 0;
for(auto p:mp){
lint x = p.first;
if(cnt>0) ans += x-xp;
cnt+=p.second;
xp = x;
}
cout<<ans<<'\n';
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... |