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;
#define all(x) x.begin() , x.end()
#define sze(x) (ll)(x.size())
typedef long long ll;
typedef pair<ll , ll> pll;
const ll maxn = 1e6 + 16 , inf = 2e18;
vector<pll> v;
int main(){
ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0);
ll n , a , b , h;
cin>>n>>a>>b;
__int128_t q = (__int128_t)1 * a * b / __gcd(a , b + 1);
h = min((__int128_t)(inf) , q);
for(ll i = 0 ; i < n ; i++){
ll l , r;
cin>>l>>r; r++;
if(r - l >= h){
cout<<h<<'\n';
return 0;
}
l %= h;
r %= h;
v.push_back({l , 1});
v.push_back({r , -1});
if(r < l){
v.push_back({0 , 1});
v.push_back({h , -1});
}
}
sort(all(v));
ll pr = 0 , cnt = 0 , ans = 0;
ll vs = sze(v);
for(ll i = 0 ; i < vs ; i++){
ll cur = v[i].first;
ans += (cnt > 0) * (cur - pr);
pr = cur;
cnt += v[i].second;
}
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... |