/**
* 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 = 30;
int a[MAX], p[MAX], q[MAX];
vector<int> qs[MAX];
vector<set<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 (qs[i].empty()) {
continue;
}
set<int> st;
for (int j = 0; j < (int) qs[i].size(); j++) {
int he = (i ^ p[qs[i][j]] ^ q[qs[i][j]]);
if (st.find(he) != st.end()) {
st.erase(st.find(he));
} else {
st.insert(he);
}
if (j % MAGIC == 0) {
my[i].push_back(st);
}
}
}
}
int question(int x, int y, int v) {
--v;
vector<int> xs;
vector<int> ys;
{
int i = lower_bound(qs[x].begin(), qs[x].end(), v + 1) - qs[x].begin();
--i;
if (i >= 0) {
set<int> st = my[x][i / MAGIC];
for (int j = (i / MAGIC) * MAGIC + 1; j <= i; j++) {
int he = (x ^ p[qs[x][j]] ^ q[qs[x][j]]);
if (st.find(he) != st.end()) {
st.erase(st.find(he));
} else {
st.insert(he);
}
}
vector<int> was(2);
for (int j : st) {
if (!was[a[j]]) {
xs.push_back(a[j]);
was[a[j]] = 1;
}
}
}
sort(xs.begin(), xs.end());
}
{
int i = lower_bound(qs[y].begin(), qs[y].end(), v + 1) - qs[y].begin();
--i;
if (i >= 0) {
set<int> st = my[y][i / MAGIC];
for (int j = (i / MAGIC) * MAGIC + 1; j <= i; j++) {
int he = (y ^ p[qs[y][j]] ^ q[qs[y][j]]);
if (st.find(he) != st.end()) {
st.erase(st.find(he));
} else {
st.insert(he);
}
}
vector<int> was(2);
for (int j : st) {
if (!was[a[j]]) {
ys.push_back(a[j]);
was[a[j]] = 1;
}
}
}
sort(ys.begin(), ys.end());
}
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;
}
if (ptr < (int) ys.size()) {
ans = min(ans, abs(xs[i] - ys[ptr]));
}
if (ptr > 0) {
ans = min(ans, abs(xs[i] - ys[ptr - 1]));
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
19536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
19792 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
168 ms |
57628 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
28452 KB |
Output is correct |
2 |
Correct |
2072 ms |
146264 KB |
Output is correct |
3 |
Correct |
1384 ms |
82968 KB |
Output is correct |
4 |
Correct |
2199 ms |
138896 KB |
Output is correct |
5 |
Correct |
381 ms |
34980 KB |
Output is correct |
6 |
Correct |
2512 ms |
138720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
20 ms |
22416 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
19536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |