# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
836753 | nonono | Strange Device (APIO19_strange_device) | C++14 | 574 ms | 68984 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.
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
int main() {
cin.tie(0)->sync_with_stdio(0);
long long n, a, b;
cin >> n >> a >> b;
long long k = a / __gcd(a, b + 1);
long long x = 1;
if(inf / k < b) x = inf + 5;
else x = b * k;
vector<pair<long long, bool>> p;
for(int i = 1; i <= n; i ++) {
long long l, r;
cin >> l >> r;
if(r - l + 1 >= x) {
cout << x << "\n";
return 0;
}
long long L = l % x;
long long R = r % x;
if(L <= R) {
p.push_back({L, true});
p.push_back({R + 1, false});
} else {
p.push_back({L, true});
p.push_back({x, false});
p.push_back({0, true});
p.push_back({R + 1, false});
}
}
sort(p.begin(), p.end());
long long total = 0;
int cnt = 0;
for(int i = 0; i < p.size(); i ++) {
if(cnt) {
total += p[i].first - p[i - 1].first;
}
cnt += (p[i].second ? 1 : -1);
}
cout << total << "\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... |