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;
const int maxN = 100000, maxU = 200000, INF = 1000000000;
int a[maxU], b[maxU], h[maxN], n, u, d;
vector<int> g[maxN];
void init(int N, int D, int H[]) {
n = N, d = D;
memcpy(h, H, sizeof(h[0]) * n);
}
void curseChanges(int U, int A[], int B[]) {
u = U;
memcpy(a, A, sizeof(a[0]) * u), memcpy(b, B, sizeof(b[0]) * u);
set<pair<int, int>> adj;
for (int i = 0; i < u; ++i) {
if (a[i] > b[i]) {
swap(a[i], b[i]);
}
if (adj.count({a[i], b[i]})) {
adj.erase({a[i], b[i]});
} else {
adj.insert({a[i], b[i]});
}
}
for (auto [x, y]: adj) {
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 0; i < n; ++i) {
sort(g[i].begin(), g[i].end(), [](int i, int j) {
return h[i] < h[j];
});
}
}
int question(int x, int y, int v) {
//i suppose that v == u
assert(v == u);
int ans = INF;
for (int to : g[x]) {
auto it = lower_bound(g[y].begin(), g[y].end(), to, [](int i, int j) {
return h[i] < h[j];
});
if (it != g[y].end()) {
ans = min(ans, h[*it] - h[to]);
}
if (it != g[y].begin()) {
ans = min(ans, h[to] - h[*prev(it)]);
}
}
return ans;
}
# | 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... |