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>
#define int long long
#define endl "\n"
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, a, b;
cin >> n >> a >> b;
long double k1 = a * (long double) b;
int k = (int) 1e18 + 1;
if (k1 <= 1e18) {
k = a * b;
}
vector<pair<int, int>> segs;
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
if (r - l + 1 >= k) {
segs.emplace_back(0, k - 1);
continue;
}
int l1 = l % k, r1 = r % k;
if (r1 < l1) {
segs.emplace_back(0, r1);
segs.emplace_back(l1, k - 1);
} else {
segs.emplace_back(l1, r1);
}
}
sort(segs.begin(), segs.end());
int mxr = -1;
int res = 0;
for (auto x : segs) {
res += max(x.second - max(mxr, x.first - 1), 0LL);
mxr = max(x.second, mxr);
}
cout << res << endl;
}
# | 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... |