이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define ll long long
#define ld long double
#define int long long
const int oo = 2e18 + 7;
bool ok(int a, int b) {
return a <= oo / b;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, a, b;
cin >> n >> a >> b;
int p = a / __gcd(a, b + 1);
if (ok(p, b)) p *= b; else p = oo;
vector<pair<int, int>> v;
while (n--) {
int l, r;
cin >> l >> r;
int L = l % p, R = r % p;
if (r - l + 1 >= p) {
L = 0;
R = p - 1;
}
l = L;
r = R;
if (l <= r) {
v.pb({l, 1});
v.pb({r + 1, -1});
} else {
v.pb({0, 1});
v.pb({r + 1, -1});
v.pb({l, 1});
v.pb({p, -1});
}
}
sort(all(v));
int ans = 0, bal = 0;
for (int i = 0; i + 1 < sz(v); i++) {
bal += v[i].y;
if (bal) ans += v[i + 1].x - v[i].x;
}
cout << ans;
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... |