#include <bits/stdc++.h>
using i64 = long long;
int n, d, u;
std::vector<int> h;
std::vector<int> a, b;
constexpr int inf = 1000000000;
void init(int N, int D, int H[]) {
n = N;
d = D;
for (int i = 0; i < n; ++i) {
h.push_back(H[i]);
}
}
void curseChanges(int U, int A[], int B[]) {
u = U;
for (int i = 0; i < u; ++i) {
a.push_back(A[i]);
b.push_back(B[i]);
}
}
int question(int x, int y, int v) {
// check
std::vector<std::unordered_set<int>> trustList(n);
for (int i = 0; i < v; ++i) {
if (trustList[a[i]].find(b[i]) == trustList[a[i]].end()) {
// insert
trustList[a[i]].insert(b[i]);
trustList[b[i]].insert(a[i]);
} else {
// erase
trustList[a[i]].erase(b[i]);
trustList[b[i]].erase(a[i]);
}
}
std::vector<std::pair<int, bool>> vals;
for (const int e : trustList[x]) {
vals.push_back({e, true});
}
for (const int e : trustList[y]) {
vals.push_back({e, false});
}
std::sort(vals.begin(), vals.end(), [&](const auto &a, const auto &b) {
return h[a.first] < h[b.first];
});
int answer = inf;
for (int i = 1; i < (int)vals.size(); ++i) {
if (vals[i - 1].second != vals[i].second) {
answer = std::min(answer, h[vals[i].first] - h[vals[i - 1].first]);
}
}
return answer;
}
/*
int main() {
int N, D, U, Q;
std::ios::sync_with_stdio(false); std::cin.tie(NULL);
std::cin >> N >> D >> U >> Q;
int *F = new int[N];
for (int i=0; i<N; i++)
std::cin >> F[i];
init(N, D, F);
int *A = new int[U], *B = new int[U];
for (int i=0; i<U; i++) {
std::cin >> A[i] >> B[i];
}
curseChanges(U, A, B);
bool correct = true;
for (int i=0; i<Q; i++) {
int X,Y,V,CorrectAnswer;
std::cin >> X >> Y >> V >> CorrectAnswer;
int YourAnswer = question(X,Y,V);
if (YourAnswer != CorrectAnswer) {
std::cout << "WA! Question: " << i
<< " (X=" << X << ", Y=" << Y << ", V=" << V << ") "
<< "Your answer: " << YourAnswer
<< " Correct Answer: " << CorrectAnswer << std::endl;
correct = false;
} else {
std::cerr << YourAnswer << " - OK" << std::endl;
}
}
if (correct) {
std::cout << "Correct." << std::endl;
} else std::cout << "Incorrect." << std::endl;
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
540 KB |
Output is correct |
2 |
Correct |
160 ms |
548 KB |
Output is correct |
3 |
Correct |
154 ms |
464 KB |
Output is correct |
4 |
Correct |
930 ms |
6840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3054 ms |
33108 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3068 ms |
32700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3035 ms |
2376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
154 ms |
540 KB |
Output is correct |
3 |
Correct |
160 ms |
548 KB |
Output is correct |
4 |
Correct |
154 ms |
464 KB |
Output is correct |
5 |
Correct |
930 ms |
6840 KB |
Output is correct |
6 |
Execution timed out |
3054 ms |
33108 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |