#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
//#include "grader.cpp"
const int MAXN = 2e5 + 25;
const int B = 300;
int n, d, h[MAXN];
void init(int N, int D, int H[]) {
n = N; d = D;
for (int i = 0; i < n; i++) {
h[i] = H[i];
}
}
int u, a[MAXN], b[MAXN];
vector <int> ii[MAXN];
vector <pair <int, vector <int>>> ls[MAXN];
int cnt[MAXN];
void curseChanges(int U, int A[], int BB[]) {
u = U;
for (int i = 0; i < u; i++) {
a[i] = A[i]; b[i] = BB[i];
}
for (int i = 0; i < n; i++) {
ls[i].push_back({-1, {}});
}
vector <int> adj2[n];
for (int i = 0; i < u; i++) {
cnt[a[i]]++; cnt[b[i]]++;
ii[a[i]].push_back(i);
ii[b[i]].push_back(i);
adj2[a[i]].push_back(b[i]);
adj2[b[i]].push_back(a[i]);
if (cnt[a[i]] % B == 0) {
ls[a[i]].push_back({i, adj2[a[i]]});
}
if (cnt[b[i]] % B == 0) {
ls[b[i]].push_back({i, adj2[b[i]]});
}
}
}
const int inf = 1e9;
set <int> get (int x, int y) {
set <int> cur;
pair <int, vector <int>> g = {y, {}};
auto h2 = lower_bound(ls[x].begin(), ls[x].end(), g);
h2--;
for (auto j : (*h2).second) {
cur.insert(j);
}
auto hh = upper_bound(ii[x].begin(), ii[x].end(), (*h2).first);
while (hh != ii[x].end() && (*hh) < y) {
int i = *hh;
if (a[i] == x) {
if (cur.count(b[i])) {
cur.erase(b[i]);
} else {
cur.insert(b[i]);
}
}
if (b[i] == x) {
if (cur.count(a[i])) {
cur.erase(a[i]);
} else {
cur.insert(a[i]);
}
}
hh++;
}
set <int> dd;
for (auto i : cur) {
dd.insert(h[i]);
}
return dd;
}
int question (int x, int y, int v) {
auto xx = get(x, v), yy = get(y, v);
int mn = inf;
for (auto i : xx) {
auto k = yy.lower_bound(i);
if (k != yy.end()) {
mn = min(mn, abs(i - *k));
}
if (k != yy.begin()) {
k--;
mn = min(mn, abs(i - *k));
}
}
return mn;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9816 KB |
Output is correct |
3 |
Correct |
5 ms |
9816 KB |
Output is correct |
4 |
Correct |
15 ms |
18068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
29428 KB |
Output is correct |
2 |
Correct |
161 ms |
29520 KB |
Output is correct |
3 |
Incorrect |
71 ms |
35144 KB |
Incorrect |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
29436 KB |
Output is correct |
2 |
Execution timed out |
3013 ms |
33064 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
11352 KB |
Output is correct |
2 |
Correct |
211 ms |
11096 KB |
Output is correct |
3 |
Incorrect |
10 ms |
11096 KB |
Incorrect |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9816 KB |
Output is correct |
3 |
Correct |
4 ms |
9816 KB |
Output is correct |
4 |
Correct |
5 ms |
9816 KB |
Output is correct |
5 |
Correct |
15 ms |
18068 KB |
Output is correct |
6 |
Correct |
140 ms |
29428 KB |
Output is correct |
7 |
Correct |
161 ms |
29520 KB |
Output is correct |
8 |
Incorrect |
71 ms |
35144 KB |
Incorrect |
9 |
Halted |
0 ms |
0 KB |
- |