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;
typedef long long ll;
const ll INF = (ll) 1e18;
ll n, a, b;
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
// freopen("input", stdin, "r");
cin >> n >> a >> b;
ll period = a / __gcd(b + 1, a);
if (INF / period < b) {
period = INF;
} else {
period *= b;
}
map<ll, int> jmen;
function<void(ll, ll)> add = [&](ll l, ll r) {
if (r - l + 1 >= period) {
jmen[0]++;
} else {
l %= period;
r %= period;
if (l <= r) {
jmen[l]++;
jmen[r + 1]--;
} else {
jmen[l]++;
jmen[period]--;
jmen[0]++;
jmen[r + 1]--;
}
}
};
for (int i = 1; i <= n; i++) {
ll l, r;
cin >> l >> r;
add(l, r);
}
jmen[period] = 0;
ll sol = 0;
int s = 0;
ll last = 0;
for (auto &i : jmen) {
if (s > 0) {
sol += i.first - last;
}
s += i.second;
last = i.first;
}
cout << sol << "\n";
return 0;
}
# | 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... |