#include "bits/stdc++.h"
using namespace std;
const int S = 1;
const int MAX_N = 2e5 + 5;
int n;
int h[MAX_N];
void init(int N, int D, int H[]) {
n = N;
for (int i = 0; i < N; ++i) {
h[i] = H[i];
}
}
set<int> f[MAX_N];
int a[MAX_N], b[MAX_N];
vector<int> chng[MAX_N];
vector<set<int>> st[MAX_N];
void edit(set<int>& se, int z) {
if (se.count(z)) se.erase(z);
else se.insert(z);
}
void curseChanges(int U, int A[], int B[]) {
for (int i = 1; i <= U; ++i) {
a[i] = A[i - 1], b[i] = B[i - 1];
}
for (int i = 0; i < n; ++i) {
chng[i].push_back(0);
st[i].emplace_back(f[i]);
}
for (int i = 1; i <= U; ++i) {
chng[a[i]].push_back(i);
chng[b[i]].push_back(i);
edit(f[a[i]], b[i]);
edit(f[b[i]], a[i]);
if (chng[a[i]].size() % S == 0) {
st[a[i]].emplace_back(f[a[i]]);
}
if (chng[b[i]].size() % S == 0) {
st[b[i]].emplace_back(f[b[i]]);
}
}
}
int get(set<int>& x, set<int>& y) {
vector<int> cx, cy;
for (auto i : x) cx.push_back(h[i]);
for (auto i : y) cy.push_back(h[i]);
sort(cx.begin(), cx.end());
sort(cy.begin(), cy.end());
int ret = 1e9;
for (int i = 0, j = 0; i < (int) x.size() && j < (int) y.size(); ) {
if (cx[i] <= cy[j]) {
ret = min(ret, cy[j] - cx[i++]);
} else {
ret = min(ret, cx[i] - cy[j++]);
}
}
return ret;
}
int question(int x, int y, int v) {
if (x == y) {
return 0;
}
int idx = upper_bound(chng[x].begin(), chng[x].end(), v) - chng[x].begin() - 1;
int idy = upper_bound(chng[y].begin(), chng[y].end(), v) - chng[y].begin() - 1;
int kx = idx - (idx % S), ky = idy - (idy % S);
assert(kx / S < (int) st[x].size());
assert(ky / S < (int) st[y].size());
assert(idx < (int) chng[x].size());
assert(idy < (int) chng[y].size());
auto sx = st[x][kx / S], sy = st[y][ky / S];
for (int i = kx + 1; i <= idx; ++i) {
int ind = chng[x][i];
int o = a[ind] ^ b[ind] ^ x;
edit(sx, o);
}
//assert(sx == f[x]);
for (int i = ky + 1; i <= idy; ++i) {
int ind = chng[y][i];
int o = a[ind] ^ b[ind] ^ y;
edit(sy, o);
}
//assert(sy == f[y]);
return get(sx, sy);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
21344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
21592 KB |
Output is correct |
2 |
Correct |
5 ms |
21592 KB |
Output is correct |
3 |
Correct |
6 ms |
21592 KB |
Output is correct |
4 |
Correct |
23 ms |
31596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
537 ms |
138120 KB |
Output is correct |
2 |
Correct |
536 ms |
138212 KB |
Output is correct |
3 |
Correct |
691 ms |
232452 KB |
Output is correct |
4 |
Runtime error |
370 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
532 ms |
138260 KB |
Output is correct |
2 |
Runtime error |
261 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
26968 KB |
Output is correct |
2 |
Correct |
96 ms |
31832 KB |
Output is correct |
3 |
Correct |
150 ms |
32600 KB |
Output is correct |
4 |
Correct |
1010 ms |
87360 KB |
Output is correct |
5 |
Correct |
1039 ms |
71684 KB |
Output is correct |
6 |
Correct |
131 ms |
33880 KB |
Output is correct |
7 |
Correct |
796 ms |
77428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
21344 KB |
Output is correct |
2 |
Correct |
5 ms |
21592 KB |
Output is correct |
3 |
Correct |
5 ms |
21592 KB |
Output is correct |
4 |
Correct |
6 ms |
21592 KB |
Output is correct |
5 |
Correct |
23 ms |
31596 KB |
Output is correct |
6 |
Correct |
537 ms |
138120 KB |
Output is correct |
7 |
Correct |
536 ms |
138212 KB |
Output is correct |
8 |
Correct |
691 ms |
232452 KB |
Output is correct |
9 |
Runtime error |
370 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |