이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |