#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxN = 100000, maxU = 200000, INF = 1000000000, BL = 500;
int a[maxU], b[maxU], h[maxN], n, u, d;
bool cmp(int i, int j) {
return (h[i] != h[j] ? h[i] < h[j] : i < j);
}
vector<int> mrg(vector<int>& A, vector<int>& B) {
vector<int> C(A.size() + B.size()), ans;
assert(is_sorted(A.begin(), A.end(), cmp));
assert(is_sorted(B.begin(), B.end(), cmp));
merge(A.begin(), A.end(), B.begin(), B.end(), C.begin(), cmp);
for (int i = 0; i < C.size();) {
int j = i;
while (j < C.size() && C[j] == C[i]) {
j += 1;
}
if ((j - i) & 1) {
ans.push_back(C[i]);
}
i = j;
}
return ans;
}
vector<vector<int>> g[maxN];
vector<int> temp[maxN];
vector<int> ti[maxN];
vector<pair<int, int>> c[maxN];
vector<pair<int, int>> ord;
int get_real(int x) {
return x;
return lower_bound(ord.begin(), ord.end(), pair(h[x], x)) - ord.begin();
}
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;
vector<int> empt;
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) {
a[i] = get_real(a[i]), b[i] = get_real(b[i]);
if (a[i] > b[i]) {
swap(a[i], b[i]);
}
temp[a[i]].push_back(b[i]);
temp[b[i]].push_back(a[i]);
c[a[i]].emplace_back(b[i], i + 1);
c[b[i]].emplace_back(a[i], i + 1);
if (adj.count({a[i], b[i]})) {
adj.erase({a[i], b[i]});
} else {
adj.insert({a[i], b[i]});
}
if (c[a[i]].size() % BL == 0) {
sort(temp[a[i]].begin(), temp[a[i]].end(), cmp);
g[a[i]].push_back(mrg(g[a[i]].empty() ? empt : g[a[i]].back(), temp[a[i]]));
ti[a[i]].push_back(i + 1);
temp[a[i]].clear();
}
if (c[b[i]].size() % BL == 0) {
sort(temp[b[i]].begin(), temp[b[i]].end(), cmp);
g[b[i]].push_back(mrg(g[b[i]].empty() ? empt : g[b[i]].back(), temp[b[i]]));
ti[b[i]].push_back(i + 1);
temp[b[i]].clear();
}
}
}
vector<int> get(int x, int v) {
int it = upper_bound(ti[x].begin(), ti[x].end(), v) - ti[x].begin() - 1, t = 0;
vector<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();
vector<int> nw;
for (; it < int(c[x].size()) && c[x][it].second <= v; ++it) {
auto [y, tt] = c[x][it];
nw.push_back(y);
}
sort(nw.begin(), nw.end(), cmp);
return mrg(ans, nw);
}
int question(int x, int y, int v) {
x = get_real(x), y = get_real(y);
int ans = INF;
vector<int> f = get(x, v), s = get(y, v);
assert(is_sorted(f.begin(), f.end(), cmp));
assert(is_sorted(s.begin(), s.end(), cmp));
int pnt = 0;
for (int to: f) {
while (pnt < s.size() && h[s[pnt]] < h[to]) {
pnt += 1;
}
if (pnt < s.size()) {
ans = min(ans, h[s[pnt]] - h[to]);
}
if (pnt > 0) {
ans = min(ans, h[to] - h[s[pnt - 1]]);
}
}
return ans;
}
Compilation message
potion.cpp: In function 'std::vector<int> mrg(std::vector<int>&, std::vector<int>&)':
potion.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int i = 0; i < C.size();) {
| ~~^~~~~~~~~~
potion.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | while (j < C.size() && C[j] == C[i]) {
| ~~^~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:114:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
114 | while (pnt < s.size() && h[s[pnt]] < h[to]) {
| ~~~~^~~~~~~~~~
potion.cpp:117:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | if (pnt < s.size()) {
| ~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9808 KB |
Output is correct |
2 |
Correct |
7 ms |
9808 KB |
Output is correct |
3 |
Correct |
7 ms |
9808 KB |
Output is correct |
4 |
Correct |
19 ms |
10608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
409 ms |
33460 KB |
Output is correct |
2 |
Correct |
481 ms |
33452 KB |
Output is correct |
3 |
Correct |
1570 ms |
17592 KB |
Output is correct |
4 |
Execution timed out |
3013 ms |
23676 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
421 ms |
33380 KB |
Output is correct |
2 |
Correct |
2005 ms |
20572 KB |
Output is correct |
3 |
Correct |
2120 ms |
24980 KB |
Output is correct |
4 |
Correct |
2424 ms |
25220 KB |
Output is correct |
5 |
Correct |
665 ms |
33120 KB |
Output is correct |
6 |
Correct |
2488 ms |
25124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
11012 KB |
Output is correct |
2 |
Correct |
227 ms |
10236 KB |
Output is correct |
3 |
Correct |
1248 ms |
10192 KB |
Output is correct |
4 |
Correct |
1718 ms |
10760 KB |
Output is correct |
5 |
Correct |
1305 ms |
10960 KB |
Output is correct |
6 |
Correct |
138 ms |
10688 KB |
Output is correct |
7 |
Correct |
1833 ms |
10368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Correct |
6 ms |
9808 KB |
Output is correct |
3 |
Correct |
7 ms |
9808 KB |
Output is correct |
4 |
Correct |
7 ms |
9808 KB |
Output is correct |
5 |
Correct |
19 ms |
10608 KB |
Output is correct |
6 |
Correct |
409 ms |
33460 KB |
Output is correct |
7 |
Correct |
481 ms |
33452 KB |
Output is correct |
8 |
Correct |
1570 ms |
17592 KB |
Output is correct |
9 |
Execution timed out |
3013 ms |
23676 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |