# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
934698 | haxorman | 이상한 기계 (APIO19_strange_device) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxN = 1e6 + 7;
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, a, b;
cin >> n >> a >> b;
__int128 p = a;
p *= b;
p /= gcd(a, b+1);
int ans = 0;
vector<pair<int,int>> ranges;
for (int i = 0; i < n; ++i) {
int l, r;
cin >> l >> r;
if (r - l + 1 >= p) {
ans = p;
}
if (r < l) {
ranges.push_back({l, p-1});
ranges.push_back({0, r});
}
else {
ranges.push_back({l, r});
}
}
if (ans == p) {
cout << ans << "\n";
exit(0);
}
sort(ranges.begin(), ranges.end());
auto [l, r] = ranges[0];
for (int i = 1; i < ranges.size(); ++i) {
auto [lb, rb] = ranges[i];
if (lb <= r) {
rb = r;
}
else {
ans += r - l + 1;
l = lb, r = rb;
}
}
ans += r - l + 1;
cout << ans << "\n";
}