# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
209158 | mieszko11b | Strange Device (APIO19_strange_device) | C++14 | 606 ms | 53436 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;
using ll = long long;
using pll = pair<ll, ll>;
#define X first
#define Y second
ll INF = ll(1e18) + 7;
int n;
ll A, B, T;
vector<pll> S;
int main() {
scanf("%d%lld%lld", &n, &A, &B);
ll d = __gcd(A, B + 1);
if(A / d <= INF / B)
T = A / d * B;
else
T = INF;
while(n--) {
ll l, r;
scanf("%lld%lld", &l, &r);
if(l / T == r / T)
S.emplace_back(l % T, r % T);
else if(l / T == r / T - 1) {
S.emplace_back(l % T, T - 1);
S.emplace_back(0, r % T);
} else {
//~ cout << l << " " << r << endl;
S.emplace_back(0, T - 1);
}
}
sort(S.begin(), S.end());
ll res = 0;
ll last = -1;
for(auto s : S) {
//~ cout << s.X << " " << s.Y << endl;
if(last < s.X)
res += s.Y - s.X + 1;
else if(last < s.Y)
res += s.Y - last;
last = max(last, s.Y);
}
printf("%lld\n", res);
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... |