#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
map<pair<int, int>, vector<int>> m;
vector<int> adj[100006];
vector<int> h;
void init(int N, int D, int H[]) {
for (int i = 0; i < N; i++) h.push_back(H[i]);
}
void curseChanges(int U, int A[], int B[]) {
for (int i = 0; i < U; i++) {
int a = A[i], b = B[i];
if (a > b) swap(a, b);
m[{ a, b }].push_back(i + 1);
adj[a].push_back(b);
adj[b].push_back(a);
}
auto it = m.begin();
while (it != m.end()) {
sort(it->second.begin(), it->second.end());
it = next(it);
}
}
struct cmp {
bool operator() (const int &a, const int &b) const {
return h[a] < h[b];
}
};
int question(int x, int y, int v) {
set<int, cmp> adjX, adjY;
for (auto &i: adj[x]) {
int a = x;
int b = i;
if (a > b) swap(a, b);
auto it = m.find({ a, b });
if (it == m.end()) continue;
int la = upper_bound(it->second.begin(), it->second.end(), v) - it->second.begin();
if (la % 2) adjX.insert(i);
}
for (auto &i: adj[y]) {
int a = y;
int b = i;
if (a > b) swap(a, b);
auto it = m.find({ a, b });
if (it == m.end()) continue;
int la = upper_bound(it->second.begin(), it->second.end(), v) - it->second.begin();
if (la % 2) adjY.insert(i);
}
if (adjX.empty() || adjY.empty()) return 1e9;
auto i = adjX.begin();
auto j = adjY.begin();
int res = 1e9;
while (i != adjX.end() && j != adjY.end()) {
res = min(res, abs(h[*i] - h[*j]));
if (h[*i] <= h[*j]) i = next(i);
else j = next(j);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2796 KB |
Output is correct |
2 |
Correct |
5 ms |
2796 KB |
Output is correct |
3 |
Correct |
5 ms |
2924 KB |
Output is correct |
4 |
Correct |
20 ms |
3952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
801 ms |
30816 KB |
Output is correct |
2 |
Correct |
774 ms |
30784 KB |
Output is correct |
3 |
Execution timed out |
3067 ms |
7904 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
775 ms |
30700 KB |
Output is correct |
2 |
Execution timed out |
3087 ms |
13416 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
4204 KB |
Output is correct |
2 |
Correct |
899 ms |
3436 KB |
Output is correct |
3 |
Execution timed out |
3040 ms |
3180 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
4 ms |
2796 KB |
Output is correct |
3 |
Correct |
5 ms |
2796 KB |
Output is correct |
4 |
Correct |
5 ms |
2924 KB |
Output is correct |
5 |
Correct |
20 ms |
3952 KB |
Output is correct |
6 |
Correct |
801 ms |
30816 KB |
Output is correct |
7 |
Correct |
774 ms |
30784 KB |
Output is correct |
8 |
Execution timed out |
3067 ms |
7904 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |