# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
145367 | dolphingarlic | Strange Device (APIO19_strange_device) | C++14 | 1016 ms | 68212 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>
#pragma GCC optimize("O3")
#define FOR(i, x, y) for (ll i = x; i < y; i++)
typedef long long ll;
using namespace std;
// Observation: pairs are periodic, period = B * (A / gcd(A, B + 1))
// We can thus "line sweep" i.e. keep a vector of events and +1 for add,
// -1 for remove and count as long as positive
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, a, b;
cin >> n >> a >> b;
ll period = b * (a / gcd(a, b + 1));
vector<pair<ll, int>> events;
FOR(i, 0, n) {
ll x, y;
cin >> x >> y;
x += period - 1;
y += period - 1;
if (y - x >= period) {
return cout << period << '\n', 0;
}
if (x % period > y % period) {
events.push_back(make_pair(1, 0));
events.push_back(make_pair(y % period + 1, 1));
# | 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... |