이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
while (b > 0) {
swap(a, b);
b %= a;
}
return a;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
long long a, b;
cin >> n >> a >> b;
long long md = (long long) 1e18 + 1;
a /= gcd(a, b + 1);
if (a <= numeric_limits<long long>::max() / b) {
md = a * b;
}
vector< pair<long long, long long> > v;
for (int i = 0; i < n; i++) {
long long l, r;
cin >> l >> r;
long long x = l % md, y = r % md;
if (x <= y) {
v.push_back({x, y});
} else {
v.push_back({x, md - 1});
v.push_back({0, y});
}
}
sort(v.begin(), v.end());
long long ans = 0;
long long l = v[0].first, r = v[0].second;
for (auto& p : v) {
if (p.first > r) {
ans += r - l + 1;
l = p.first;
r = p.second;
} else {
r = max(r, p.second);
}
}
ans += r - l + 1;
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... |