#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif
using namespace std;
constexpr int N = 1E5 + 5, B = 2, D = 2;
int h[N], n;
vector<pair<int, int>> mv[N];
void init(int N, int D, int H[]) {
n = N;
for (int i = 0; i < n; i++) {
h[i] = H[i];
}
}
void curseChanges(int U, int A[], int B[]) {
for (int i = 0; i < U; i++) {
mv[A[i]].emplace_back(i, B[i]);
mv[B[i]].emplace_back(i, A[i]);
}
}
int question(int x, int y, int v) {
multiset<int> a, ha;
multiset<int> b, hb;
for (int i = 0; i < int(mv[x].size()) && mv[x][i].first < v; i++) {
int g = mv[x][i].second;
if (a.count(g)) {
a.erase(g);
ha.erase(ha.find(h[g]));
} else {
a.insert(g);
ha.insert(h[g]);
}
}
for (int i = 0; i < int(mv[y].size()) && mv[y][i].first < v; i++) {
int g = mv[y][i].second;
if (b.count(g)) {
b.erase(g);
hb.erase(hb.find(h[g]));
} else {
b.insert(g);
hb.insert(h[g]);
}
}
vector<int> B(hb.begin(), hb.end());
int i = 0;
int ans = 1E9;
for (auto x : ha) {
while (i < int(B.size()) && B[i] < x)
i++;
if (i > 0) {
ans = min(ans, x - B[i - 1]);
}
if (i < int(B.size())) {
ans = min(ans, B[i] - x);
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2640 KB |
Output is correct |
2 |
Correct |
3 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
19 ms |
3488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
11252 KB |
Output is correct |
2 |
Correct |
182 ms |
11216 KB |
Output is correct |
3 |
Execution timed out |
3075 ms |
8620 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
11212 KB |
Output is correct |
2 |
Execution timed out |
3089 ms |
9592 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
3100 KB |
Output is correct |
2 |
Correct |
419 ms |
3024 KB |
Output is correct |
3 |
Execution timed out |
3079 ms |
2944 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
3 ms |
2640 KB |
Output is correct |
3 |
Correct |
3 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
19 ms |
3488 KB |
Output is correct |
6 |
Correct |
212 ms |
11252 KB |
Output is correct |
7 |
Correct |
182 ms |
11216 KB |
Output is correct |
8 |
Execution timed out |
3075 ms |
8620 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |