#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T>
using uset = unordered_set<T>;
const int maxN = 100000, maxU = 200000, INF = 1000000000, BL = 300;
int a[maxU], b[maxU], h[maxN], n, u, d;
vector<uset<int>> g[maxN];
uset<int> temp[maxN];
vector<int> ti[maxN];
vector<pair<int, int>> c[maxN];
void init(int N, int D, int H[]) {
n = N, d = D;
memcpy(h, H, sizeof(h[0]) * n);
}
void curseChanges(int U, int A[], int B[]) {
u = U;
memcpy(a, A, sizeof(a[0]) * u), memcpy(b, B, sizeof(b[0]) * u);
set<pair<int, int>> adj;
for (int i = 0; i < u; ++i) {
if (a[i] > b[i]) {
swap(a[i], b[i]);
}
if (adj.count({a[i], b[i]})) {
adj.erase({a[i], b[i]});
c[a[i]].emplace_back(~b[i], i + 1);
c[b[i]].emplace_back(~a[i], i + 1);
temp[a[i]].erase(b[i]);
temp[b[i]].erase(a[i]);
} else {
adj.insert({a[i], b[i]});
c[a[i]].emplace_back(b[i], i + 1);
c[b[i]].emplace_back(a[i], i + 1);
temp[a[i]].insert(b[i]);
temp[b[i]].insert(a[i]);
}
if (c[a[i]].size() % BL == 0) {
g[a[i]].push_back(temp[a[i]]);
ti[a[i]].push_back(i + 1);
}
if (c[b[i]].size() % BL == 0) {
g[b[i]].push_back(temp[b[i]]);
ti[b[i]].push_back(i + 1);
}
}
}
vector<int> get(int x, int v) {
int it = upper_bound(ti[x].begin(), ti[x].end(), v) - ti[x].begin() - 1, t = 0;
uset<int> ans;
if (it > -1) {
ans = g[x][it];
t = ti[x][it] + 1;
}
it = lower_bound(c[x].begin(), c[x].end(), make_pair(-1, t), [](pair<int, int> a, pair<int, int> b) {
return a.second < b.second;
}) - c[x].begin();
int cnt = 0;
for (; it < int(c[x].size()) && c[x][it].second <= v; ++it) {
auto [y, tt] = c[x][it];
if (y < 0) {
ans.erase(~y);
} else {
ans.insert(y);
}
cnt += 1;
}
assert(cnt <= BL);
vector<int> answer(ans.begin(), ans.end());
return answer;
}
int question(int x, int y, int v) {
int ans = INF;
vector<int> f = get(x, v), s = get(y, v);
sort(s.begin(), s.end(), [](int i, int j) {
return h[i] < h[j];
});
for (int to: f) {
int L = -1, R = s.size();
while (L + 1 < R) {
int M = (L + R) >> 1;
if (h[s[M]] >= h[to]) {
R = M;
} else {
L = M;
}
}
if (R != s.size()) {
ans = min(ans, h[s[R]] - h[to]);
}
if (R > 0) {
ans = min(ans, h[to] - h[s[R - 1]]);
}
}
return ans;
}
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:99:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | if (R != s.size()) {
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
13008 KB |
Output is correct |
2 |
Correct |
8 ms |
13008 KB |
Output is correct |
3 |
Correct |
8 ms |
13064 KB |
Output is correct |
4 |
Correct |
21 ms |
13948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
538 ms |
54972 KB |
Output is correct |
2 |
Correct |
531 ms |
54932 KB |
Output is correct |
3 |
Correct |
649 ms |
21000 KB |
Output is correct |
4 |
Execution timed out |
3061 ms |
40688 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
562 ms |
54996 KB |
Output is correct |
2 |
Execution timed out |
3090 ms |
36884 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
15460 KB |
Output is correct |
2 |
Correct |
191 ms |
13392 KB |
Output is correct |
3 |
Correct |
593 ms |
13392 KB |
Output is correct |
4 |
Correct |
1997 ms |
14892 KB |
Output is correct |
5 |
Correct |
1923 ms |
15368 KB |
Output is correct |
6 |
Correct |
164 ms |
14544 KB |
Output is correct |
7 |
Correct |
1790 ms |
13648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12752 KB |
Output is correct |
2 |
Correct |
10 ms |
13008 KB |
Output is correct |
3 |
Correct |
8 ms |
13008 KB |
Output is correct |
4 |
Correct |
8 ms |
13064 KB |
Output is correct |
5 |
Correct |
21 ms |
13948 KB |
Output is correct |
6 |
Correct |
538 ms |
54972 KB |
Output is correct |
7 |
Correct |
531 ms |
54932 KB |
Output is correct |
8 |
Correct |
649 ms |
21000 KB |
Output is correct |
9 |
Execution timed out |
3061 ms |
40688 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |