#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif
using namespace std;
constexpr int N = 1E5 + 5, D = 40;
int h[N], n;
vector<pair<int, int>> mv[N];
vector<set<pair<int, int>>> s[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]);
}
for (int i = 0; i < n; i++) {
int z = mv[i].size();
set<pair<int, int>> v;
for (int j = 0; j < z; j++) {
if (j % D == 0) {
s[i].push_back(v);
}
if (v.count({h[mv[i][j].second], mv[i][j].second}))
v.erase({h[mv[i][j].second], mv[i][j].second});
else
v.insert({h[mv[i][j].second], mv[i][j].second});
}
}
}
int question(int x, int y, int v) {
if (v == 0)
return 1E9;
int F = lower_bound(mv[x].begin(), mv[x].end(), pair(v, -1)) - mv[x].begin() - 1;
int S = lower_bound(mv[y].begin(), mv[y].end(), pair(v, -1)) - mv[y].begin() - 1;
if (F == -1 || S == -1)
return 1E9;
set<pair<int, int>> a = s[x][F / D], b = s[y][S / D];
for (int i = F / D * D; i <= F; i++) {
int g = mv[x][i].second;
if (a.count({h[g], g})) {
a.erase({h[g], g});
} else {
a.insert({h[g], g});
}
}
for (int i = S / D * D; i <= S; i++) {
int g = mv[y][i].second;
if (b.count({h[g], g})) {
b.erase({h[g], g});
} else {
b.insert({h[g], g});
}
}
vector<pair<int, int>> B(b.begin(), b.end());
int i = 0;
int ans = 1E9;
for (auto [x, y] : a) {
while (i < int(B.size()) && B[i].first < x)
i++;
if (i > 0) {
ans = min(ans, x - B[i - 1].first);
}
if (i < int(B.size())) {
ans = min(ans, B[i].first - x);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5072 KB |
Output is correct |
2 |
Correct |
4 ms |
5072 KB |
Output is correct |
3 |
Correct |
4 ms |
5072 KB |
Output is correct |
4 |
Correct |
20 ms |
5960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
202 ms |
19400 KB |
Output is correct |
2 |
Correct |
212 ms |
19476 KB |
Output is correct |
3 |
Correct |
389 ms |
15692 KB |
Output is correct |
4 |
Correct |
1863 ms |
70016 KB |
Output is correct |
5 |
Correct |
634 ms |
20968 KB |
Output is correct |
6 |
Execution timed out |
3098 ms |
102344 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
247 ms |
19452 KB |
Output is correct |
2 |
Correct |
2587 ms |
108440 KB |
Output is correct |
3 |
Correct |
1688 ms |
60260 KB |
Output is correct |
4 |
Correct |
2822 ms |
102100 KB |
Output is correct |
5 |
Correct |
415 ms |
24392 KB |
Output is correct |
6 |
Correct |
2981 ms |
102088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
5968 KB |
Output is correct |
2 |
Correct |
210 ms |
5512 KB |
Output is correct |
3 |
Correct |
325 ms |
5584 KB |
Output is correct |
4 |
Correct |
1159 ms |
7524 KB |
Output is correct |
5 |
Correct |
1012 ms |
7200 KB |
Output is correct |
6 |
Correct |
191 ms |
5432 KB |
Output is correct |
7 |
Correct |
1006 ms |
6848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4944 KB |
Output is correct |
2 |
Correct |
5 ms |
5072 KB |
Output is correct |
3 |
Correct |
4 ms |
5072 KB |
Output is correct |
4 |
Correct |
4 ms |
5072 KB |
Output is correct |
5 |
Correct |
20 ms |
5960 KB |
Output is correct |
6 |
Correct |
202 ms |
19400 KB |
Output is correct |
7 |
Correct |
212 ms |
19476 KB |
Output is correct |
8 |
Correct |
389 ms |
15692 KB |
Output is correct |
9 |
Correct |
1863 ms |
70016 KB |
Output is correct |
10 |
Correct |
634 ms |
20968 KB |
Output is correct |
11 |
Execution timed out |
3098 ms |
102344 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |