#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, C = 6;
int H[100000];
bool odd[100000];
vector<int> u_times[100000];
vector<vector<int>> trust[100000];
struct cmp {
bool operator()(pair<int, int> a, pair<int, int> b) const {
return tie(H[a.second], a.first) < tie(H[b.second], b.first);
}
};
vector<set<pair<int, int>, cmp>> updates[100000];
void init(int N, int D, int H[]) {
for (int i = 0; i < N; i++) {
trust[i].push_back({});
updates[i].push_back({});
u_times[i].push_back(0);
::H[i] = H[i];
}
}
vector<int> playback(int s, int t) {
int ub = upper_bound(u_times[s].begin(), u_times[s].end(), t) - u_times[s].begin() - 1;
vector<int> orig = trust[s][ub];
set<pair<int, int>, cmp> upd = updates[s][ub];
for (int i : orig) odd[i] ^= 1;
for (pair<int, int> i : upd) {
if (i.first >= t) continue;
odd[i.second] ^= 1;
}
vector<int> ret1, ret2;
for (int i : orig) if (odd[i]) ret1.push_back(i), odd[i] = 0;
for (pair<int, int> i : upd) {
if (i.first >= t) continue;
if (odd[i.second]) ret2.push_back(i.second), odd[i.second] = 0;
}
vector<int> mrg;
int ptr1 = 0, ptr2 = 0;
while (ptr1 < ret1.size() && ptr2 < ret2.size()) {
if (H[ret1[ptr1]] < H[ret2[ptr2]]) mrg.push_back(ret1[ptr1++]);
else mrg.push_back(ret2[ptr2++]);
}
while (ptr1 < ret1.size()) mrg.push_back(ret1[ptr1++]);
while (ptr2 < ret2.size()) mrg.push_back(ret2[ptr2++]);
return mrg;
}
void curseChanges(int U, int A[], int B[]) {
for (int i = 0; i < U; i++) {
updates[A[i]].back().insert({i, B[i]});
updates[B[i]].back().insert({i, A[i]});
if (updates[A[i]].back().size() == C) {
trust[A[i]].push_back(playback(A[i], i + 1));
updates[A[i]].push_back({});
u_times[A[i]].push_back(i + 1);
}
if (updates[B[i]].back().size() == C) {
trust[B[i]].push_back(playback(B[i], i + 1));
updates[B[i]].push_back({});
u_times[B[i]].push_back(i + 1);
}
}
}
int question(int x, int y, int v) {
vector<int> sx = playback(x, v);
vector<int> sy = playback(y, v);
int ans = INF;
for (int xptr = 0, yptr = 0; xptr != sx.size() && yptr != sy.size();) {
ans = min(ans, abs(H[sx[xptr]] - H[sy[yptr]]));
if (H[sx[xptr]] <= H[sy[yptr]]) xptr++;
else yptr++;
}
return ans;
}
Compilation message
potion.cpp: In function 'std::vector<int> playback(int, int)':
potion.cpp:43:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | while (ptr1 < ret1.size() && ptr2 < ret2.size()) {
| ~~~~~^~~~~~~~~~~~~
potion.cpp:43:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | while (ptr1 < ret1.size() && ptr2 < ret2.size()) {
| ~~~~~^~~~~~~~~~~~~
potion.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | while (ptr1 < ret1.size()) mrg.push_back(ret1[ptr1++]);
| ~~~~~^~~~~~~~~~~~~
potion.cpp:48:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | while (ptr2 < ret2.size()) mrg.push_back(ret2[ptr2++]);
| ~~~~~^~~~~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:73:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int xptr = 0, yptr = 0; xptr != sx.size() && yptr != sy.size();) {
| ~~~~~^~~~~~~~~~~~
potion.cpp:73:60: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int xptr = 0, yptr = 0; xptr != sx.size() && yptr != sy.size();) {
| ~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7660 KB |
Output is correct |
2 |
Correct |
8 ms |
7660 KB |
Output is correct |
3 |
Correct |
7 ms |
7660 KB |
Output is correct |
4 |
Correct |
42 ms |
20844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
484 ms |
44596 KB |
Output is correct |
2 |
Correct |
560 ms |
44652 KB |
Output is correct |
3 |
Correct |
441 ms |
51948 KB |
Output is correct |
4 |
Correct |
1079 ms |
85280 KB |
Output is correct |
5 |
Correct |
662 ms |
44364 KB |
Output is correct |
6 |
Correct |
1746 ms |
102124 KB |
Output is correct |
7 |
Correct |
634 ms |
52076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
521 ms |
44524 KB |
Output is correct |
2 |
Correct |
1375 ms |
103540 KB |
Output is correct |
3 |
Correct |
1038 ms |
74352 KB |
Output is correct |
4 |
Correct |
1427 ms |
101996 KB |
Output is correct |
5 |
Correct |
561 ms |
49004 KB |
Output is correct |
6 |
Correct |
1524 ms |
101996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
9708 KB |
Output is correct |
2 |
Correct |
147 ms |
10220 KB |
Output is correct |
3 |
Correct |
177 ms |
10476 KB |
Output is correct |
4 |
Correct |
459 ms |
11244 KB |
Output is correct |
5 |
Correct |
427 ms |
10860 KB |
Output is correct |
6 |
Correct |
159 ms |
9068 KB |
Output is correct |
7 |
Correct |
396 ms |
11116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
7 ms |
7660 KB |
Output is correct |
3 |
Correct |
8 ms |
7660 KB |
Output is correct |
4 |
Correct |
7 ms |
7660 KB |
Output is correct |
5 |
Correct |
42 ms |
20844 KB |
Output is correct |
6 |
Correct |
484 ms |
44596 KB |
Output is correct |
7 |
Correct |
560 ms |
44652 KB |
Output is correct |
8 |
Correct |
441 ms |
51948 KB |
Output is correct |
9 |
Correct |
1079 ms |
85280 KB |
Output is correct |
10 |
Correct |
662 ms |
44364 KB |
Output is correct |
11 |
Correct |
1746 ms |
102124 KB |
Output is correct |
12 |
Correct |
634 ms |
52076 KB |
Output is correct |
13 |
Correct |
521 ms |
44524 KB |
Output is correct |
14 |
Correct |
1375 ms |
103540 KB |
Output is correct |
15 |
Correct |
1038 ms |
74352 KB |
Output is correct |
16 |
Correct |
1427 ms |
101996 KB |
Output is correct |
17 |
Correct |
561 ms |
49004 KB |
Output is correct |
18 |
Correct |
1524 ms |
101996 KB |
Output is correct |
19 |
Correct |
72 ms |
9708 KB |
Output is correct |
20 |
Correct |
147 ms |
10220 KB |
Output is correct |
21 |
Correct |
177 ms |
10476 KB |
Output is correct |
22 |
Correct |
459 ms |
11244 KB |
Output is correct |
23 |
Correct |
427 ms |
10860 KB |
Output is correct |
24 |
Correct |
159 ms |
9068 KB |
Output is correct |
25 |
Correct |
396 ms |
11116 KB |
Output is correct |
26 |
Correct |
810 ms |
68340 KB |
Output is correct |
27 |
Correct |
1117 ms |
74476 KB |
Output is correct |
28 |
Correct |
1147 ms |
71404 KB |
Output is correct |
29 |
Correct |
1114 ms |
85228 KB |
Output is correct |
30 |
Correct |
1754 ms |
102120 KB |
Output is correct |
31 |
Correct |
1619 ms |
104428 KB |
Output is correct |
32 |
Correct |
1646 ms |
102124 KB |
Output is correct |