| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 871705 | serifefedartar | 이상한 기계 (APIO19_strange_device) | C++17 | 670 ms | 88876 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;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+9;
const ll LOGN = 20;
const ll MAXN = 6 * 1e6 + 50;
vector<pair<ll,ll>> v;
vector<ll> cc;
ll calc(ll A, ll B) {
if (1e18 / A < B)
return 1e18;
if (1e18 / B < A)
return 1e18;
return A * B;
}
int index(ll k) {
return upper_bound(cc.begin(), cc.end(), k) - cc.begin();
}
ll cnt[MAXN];
int main() {
fast
ll n, A, B;
cin >> n >> A >> B;
ll period = calc(A, B);
for (int i = 1; i <= n; i++) {
ll l, r;
cin >> l >> r;
ll left_mod = l % period;
ll right_mod = r % period;
if (r - l + 1 > period - left_mod) {
v.push_back({left_mod, period - 1});
v.push_back({0, right_mod});
} else
v.push_back({left_mod, right_mod});
}
for (auto u : v) {
cc.push_back(u.f);
cc.push_back(u.s);
cc.push_back(u.s+1);
}
sort(cc.begin(), cc.end());
cc.erase(unique(cc.begin(), cc.end()), cc.end());
for (auto u : v) {
cnt[index(u.f)]++;
cnt[index(u.s + 1)]--;
}
for (int i = 1; i < MAXN; i++)
cnt[i] += cnt[i-1];
ll ans = 0;
for (int i = 0; i < cc.size() - 1; i++) {
if (cnt[i+1]) {
ans += cc[i+1] - cc[i];
}
}
cout << ans << "\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... | ||||
