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 int ll;
typedef long double ld;
#define sync ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
const ll inf = 2e18;
int main()
{
int n;
ll A, B, AB;
cin >> n >> A >> B;
A /= __gcd(A, (B + 1));
if(inf / A >= B)
AB = A * B;
else
AB = inf;
vector<pair<ll, ll> > vec;
bool check = false;
for(int i = 0; i < n; i++)
{
ll l, r;
cin >> l >> r;
if(check)
{
continue;
}
if(r - l + 1 >= AB)
{
check = true;
continue;
}
r %= AB, l %= AB;
if(l > r)
{
vec.pb(mp(0, r));
vec.pb(mp(l, AB - 1));
}
else
vec.pb(mp(l, r));
}
sort(vec.begin(), vec.end());
ll ans = 0, mx = -1;
for(auto tmp : vec)
{
ll x = tmp.fi, y = tmp.se;
if(mx < x)
ans += y - x + 1;
else
ans += max(ll(0), y - mx);
mx = max(mx, y);
}
if(check)
ans = AB;
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... |