/**
* author: wxhtzdy
* created: 01.07.2022 22:14:54
**/
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
const int MAX = 200005;
const int MAGIC = 400;
int a[MAX], p[MAX], q[MAX];
vector<int> qs[MAX];
vector<vector<int>> my[MAX];
void init(int n, int d, int h[]) {
for (int i = 0; i < n; i++) {
a[i] = h[i];
}
}
void curseChanges(int u, int a[], int b[]) {
for (int i = 0; i < u; i++) {
qs[a[i]].push_back(i);
qs[b[i]].push_back(i);
p[i] = a[i];
q[i] = b[i];
}
for (int i = 0; i < MAX; i++) {
if ((int) qs[i].size() <= MAGIC) {
continue;
}
set<int> st;
for (int j : qs[i]) {
int he = (i ^ p[j] ^ q[j]);
if (st.find(he) != st.end()) {
st.erase(st.find(he));
} else {
st.insert(he);
}
vector<int> vec;
for (int f : st) {
vec.push_back(::a[f]);
}
sort(vec.begin(), vec.end());
my[i].push_back(vec);
}
}
}
int question(int x, int y, int v) {
--v;
vector<int> xs;
vector<int> ys;
if ((int) qs[x].size() <= MAGIC) {
set<int> st;
for (int i = 0; i < (int) qs[x].size(); i++) {
if (qs[x][i] > v) {
break;
}
int he = (x ^ p[qs[x][i]] ^ q[qs[x][i]]);
if (st.find(he) != st.end()) {
st.erase(st.find(he));
} else {
st.insert(he);
}
}
for (int i : st) {
xs.push_back(a[i]);
}
sort(xs.begin(), xs.end());
} else {
int i = lower_bound(qs[x].begin(), qs[x].end(), v + 1) - qs[x].begin();
--i;
if (i >= 0 && i < (int) my[x].size()) {
for (int vv : my[x][i]) {
xs.push_back(vv);
}
}
}
if ((int) qs[y].size() <= MAGIC) {
set<int> st;
for (int i = 0; i < (int) qs[y].size(); i++) {
if (qs[y][i] > v) {
break;
}
int he = (y ^ p[qs[y][i]] ^ q[qs[y][i]]);
if (st.find(he) != st.end()) {
st.erase(st.find(he));
} else {
st.insert(he);
}
}
for (int i : st) {
ys.push_back(a[i]);
}
sort(ys.begin(), ys.end());
} else {
int i = lower_bound(qs[y].begin(), qs[y].end(), v + 1) - qs[y].begin();
--i;
if (i >= 0 && i < (int) my[y].size()) {
for (int vv : my[y][i]) {
ys.push_back(vv);
}
}
}
int ptr = 0;
int ans = 1e9;
for (int i = 0; i < (int) xs.size(); i++) {
while (ptr + 1 < (int) ys.size() && xs[i] > ys[ptr]) {
ptr += 1;
}
for (int j = -1; j <= 1; j++) {
int idx = ptr + j;
if (idx >= 0 && idx < (int) ys.size()) {
ans = min(ans, abs(xs[i] - ys[idx]));
}
}
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int H[6];
H[0] = 2;
H[1] = 42;
H[2] = 1000;
H[3] = 54;
H[4] = 68;
H[5] = 234;
init(6, 5, H);
int A[11], B[11];
A[0] = 0;
A[1] = 2;
A[2] = 3;
A[3] = 3;
A[4] = 3;
A[5] = 1;
A[6] = 5;
A[7] = 0;
A[8] = 3;
A[9] = 1;
A[10] = 3;
B[0] = 1;
B[1] = 0;
B[2] = 4;
B[3] = 5;
B[4] = 5;
B[5] = 3;
B[6] = 3;
B[7] = 5;
B[8] = 0;
B[9] = 3;
B[10] = 5;
curseChanges(11, A, B);
cout << question(0, 3, 4) << '\n';
cout << question(3, 0, 8) << '\n';
cout << question(0, 5, 5) << '\n';
cout << question(3, 0, 11) << '\n';
return 0;
}
Compilation message
/usr/bin/ld: /tmp/ccAIk5Tn.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cckb6ntl.o:potion.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status