# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
497796 | MilosMilutinovic | Strange Device (APIO19_strange_device) | C++14 | 643 ms | 86224 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;
int n;
ll A, B;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(11);
cerr << fixed << setprecision(6);
cin >> n >> A >> B;
A /= __gcd(A, B + 1);
ll mod = 1e18 + 1;
if (A <= (LLONG_MAX / 2) / B) mod = A * B;
vector<pair<ll, ll>> vec;
for (int i = 0; i < n; ++i) {
ll l, r;
cin >> l >> r;
ll len = r - l + 1;
if (len >= mod) {
cout << mod << "\n";
return 0;
}
l = l % mod;
r = r % mod;
if (l <= r) {
vec.push_back({l, r});
} else {
vec.push_back({l, mod - 1});
vec.push_back({0, r});
}
}
vector<pair<ll, int>> Events;
for (int i = 0; i < vec.size(); ++i) {
Events.push_back({vec[i].first, 0});
Events.push_back({vec[i].second, 1});
}
sort(Events.begin(), Events.end());
int bal = 0;
ll left = 0, tot = 0;
for (auto ev : Events) {
if (ev.second == 0) {
bal++;
if (bal == 1) left = ev.first;
} else {
bal--;
if (bal == 0) tot += ev.first - left + 1;
}
}
cout << tot << "\n";
}
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... |