# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
171757 | Sensei | Strange Device (APIO19_strange_device) | C++17 | 689 ms | 31508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
DATE: 2019-12-30 11:10:15
NAME:
PROBLEM: APIO19_strange_device
*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
const long long LLINF = 1e18 + 100;
class Segment {
public:
long long l, r;
Segment() {}
Segment(long long x, long long y) {
l = x;
r = y;
}
};
long long f(long long x, long long y) {
if (x / __gcd(x, y + 1) > LLINF / y) {
return LLINF;
}
return x / __gcd(x, y + 1) * y;
}
int main() {
int n;
cin >> n;
long long A, B;
cin >> A >> B;
long long C = f(A, B);
vector<Segment> segments;
for (int i = 1; i <= n; i++) {
Segment segment;
scanf("%lld %lld", &segment.l, &segment.r);
if (segment.r - segment.l + 1 >= C) {
cout << C << "\n";
return 0;
}
segment.l %= C;
segment.r %= C;
if (segment.l <= segment.r) {
segments.push_back(segment);
}
else {
segments.push_back(Segment(0, segment.r));
segments.push_back(Segment(segment.l, C - 1));
}
}
sort(segments.begin(), segments.end(), [](Segment x, Segment y) {
if (x.l == y.l) {
return x.r < y.r;
}
return x.l < y.l;
});
long long lastr = -1;
long long ans = 0;
for (int i = 0; i < segments.size(); i++) {
if (segments[i].l > lastr) {
lastr = segments[i].l - 1;
}
if (segments[i].r > lastr) {
ans += segments[i].r - lastr;
lastr = segments[i].r;
}
}
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
# | 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... |