# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153890 | DystoriaX | Strange Device (APIO19_strange_device) | C++14 | 626 ms | 19280 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;
int n;
long long a, b, mx;
vector<pair<long long, long long> > seg;
long long gcd(long long a, long long b){
if(b == 0) return a;
return gcd(b, a % b);
}
int main(){
scanf("%d%lld%lld", &n, &a, &b);
mx = a / gcd(a, b + 1);
if(log10l(mx) + log10l(b) >= 18){
mx = 1000000000000000000LL;
} else mx *= b;
for(int i = 0; i < n; i++){
long long l, r;
scanf("%lld%lld", &l, &r);
l %= mx, r %= mx;
if(r - l + 1 >= mx){
seg.emplace_back(0, mx - 1);
} else if (l <= r){
seg.emplace_back(l, r);
} else {
seg.emplace_back(l, mx - 1);
seg.emplace_back(0, r);
}
}
sort(seg.begin(), seg.end());
long long ans = 0, last = 0;
for(auto k : seg){
ans += max(0LL, k.second - max(last, k.first) + 1);
last = max(last, k.second + 1);
}
printf("%lld\n", ans);
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... |