#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;
int n, rad;
int *H0, *A0, *B0;
vi Perm;
vector<vector<vi> > Snapshot;
vector<set<int> > S;
void init(int N, int D, int H[]) {
n = N;
H0 = H;
S.resize(n);
for(int i = 0; i < n; ++i)
Perm.push_back(i);
sort(Perm.begin(), Perm.end(), [&](auto a, auto b) {
return H[a] < H[b];
});
}
void curseChanges(int U, int A[], int B[]) {
rad = max(int(sqrt(U)) / 2, 1);
A0 = A;
B0 = B;
for(int nr = 0; nr < U; ++nr) {
if(nr % rad == 0) {
vector<vi> Nou;
for(int i = 0; i < n; ++i) {
vi V;
for(auto it : S[i]) V.push_back(it);
Nou.push_back(V);
}
Snapshot.push_back(Nou);
}
int a = A[nr], b = B[nr];
if(S[a].count(b)) {
S[a].erase(b);
S[b].erase(a);
} else {
S[b].insert(a);
S[a].insert(b);
}
}
}
const int INF = 1e9;
int question(int x, int y, int v) {
if(!v) {
return INF;
}
--v;
vi VSX = Snapshot[v / rad][x];
vi VSY = Snapshot[v / rad][y];
set<int> SX, SY;
for(auto it : VSX) SX.insert(it);
for(auto it : VSY) SY.insert(it);
for(int i = v / rad * rad; i <= v; ++i) {
int a = A0[i], b = B0[i];
if(b == x) swap(a, b);
if(a == x) {
if(SX.count(b)) SX.erase(b);
else SX.insert(b);
}
if(b == y) swap(a, b);
if(a == y) {
if(SY.count(b)) SY.erase(b);
else SY.insert(b);
}
}
vi VA, VB;
for(auto it : SX)
VA.push_back(H0[it]);
for(auto it : SY)
VB.push_back(H0[it]);
sort(VA.begin(), VA.end());
sort(VB.begin(), VB.end());
int p1 = 0, p2 = 0;
int re = INF;
while(p1 < VA.size() && p2 < VB.size()) {
re = min(re, abs(VB[p2] - VA[p1]));
if(VA[p1] < VB[p2]) ++p1;
else ++p2;
}
return re;
}
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:88:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | while(p1 < VA.size() && p2 < VB.size()) {
| ~~~^~~~~~~~~~~
potion.cpp:88:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | while(p1 < VA.size() && p2 < VB.size()) {
| ~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
3668 KB |
Output is correct |
2 |
Correct |
9 ms |
3388 KB |
Output is correct |
3 |
Correct |
8 ms |
3200 KB |
Output is correct |
4 |
Correct |
162 ms |
168524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
425 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
412 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
273 ms |
84848 KB |
Output is correct |
2 |
Correct |
151 ms |
49472 KB |
Output is correct |
3 |
Correct |
259 ms |
49100 KB |
Output is correct |
4 |
Correct |
1212 ms |
70020 KB |
Output is correct |
5 |
Correct |
1533 ms |
79580 KB |
Output is correct |
6 |
Correct |
187 ms |
16724 KB |
Output is correct |
7 |
Correct |
964 ms |
52836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
3668 KB |
Output is correct |
3 |
Correct |
9 ms |
3388 KB |
Output is correct |
4 |
Correct |
8 ms |
3200 KB |
Output is correct |
5 |
Correct |
162 ms |
168524 KB |
Output is correct |
6 |
Runtime error |
425 ms |
262144 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |