#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;
int n;
int *H0, *A0, *B0;
int rad = 10000000;
struct SetRollback {
vector<int> T, V;
vector<vi> Snap;
set<int> S;
void update(int t, int v) {
if(T.size() % rad == 0) {
vi W;
for(auto it : S) W.push_back(it);
Snap.push_back(W);
}
T.push_back(t);
V.push_back(v);
if(S.count(v)) S.erase(v);
else S.insert(v);
}
vi val(int t) {
if(T.empty()) return vi();
int st = 0, dr = int(T.size()) - 1, mij;
while(st < dr) {
mij = (st + dr + 1) / 2;
if(T[mij] <= t) st = mij;
else dr = mij - 1;
}
vi E = Snap[st / rad];
set<int> SV;
for(auto it : E) SV.insert(it);
for(int i = st / rad * rad; i <= st; ++i) {
int v = V[i];
if(SV.count(v)) SV.erase(v);
else SV.insert(v);
}
vi A;
for(auto it : SV) A.push_back(it);
return A;
}
};
vector<SetRollback> V;
void init(int N, int D, int H[]) {
n = N;
H0 = H;
V.resize(n);
}
void curseChanges(int U, int A[], int B[]) {
A0 = A; B0 = B;
for(int i = 0; i < U; ++i) {
int a = A[i], b = B[i];
V[a].update(i + 1, b);
V[b].update(i + 1, a);
}
}
const int INF = 1e9;
int question(int x, int y, int v) {
vi X = V[x].val(v);
vi Y = V[y].val(v);
vi VA, VB;
for(auto it : X) VA.push_back(H0[it]);
for(auto it : Y) 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:92:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | while(p1 < VA.size() && p2 < VB.size()) {
| ~~~^~~~~~~~~~~
potion.cpp:92:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | while(p1 < VA.size() && p2 < VB.size()) {
| ~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
756 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
345 ms |
44592 KB |
Output is correct |
2 |
Correct |
337 ms |
44768 KB |
Output is correct |
3 |
Execution timed out |
3049 ms |
17936 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
269 ms |
44700 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
3672 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
756 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |