#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#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 = 10;
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() || T[0] > t) 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;
}
unordered_map<int, int> Fr;
for(int i = st / rad * rad; i <= st; ++i)
++Fr[V[i]];
vi A;
for(auto it : Snap[st / rad]) {
if(Fr[it] & 1);
else A.push_back(it);
Fr[it] = 0;
}
for(auto [it, v] : Fr)
if(v & 1) 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 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
15 ms |
13104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
355 ms |
44612 KB |
Output is correct |
2 |
Correct |
345 ms |
44860 KB |
Output is correct |
3 |
Correct |
220 ms |
20844 KB |
Output is correct |
4 |
Correct |
2749 ms |
36980 KB |
Output is correct |
5 |
Correct |
726 ms |
32976 KB |
Output is correct |
6 |
Execution timed out |
3044 ms |
58620 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
356 ms |
44448 KB |
Output is correct |
2 |
Execution timed out |
3049 ms |
53380 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
3416 KB |
Output is correct |
2 |
Correct |
128 ms |
2140 KB |
Output is correct |
3 |
Correct |
221 ms |
2004 KB |
Output is correct |
4 |
Correct |
1319 ms |
3672 KB |
Output is correct |
5 |
Correct |
1440 ms |
3672 KB |
Output is correct |
6 |
Correct |
167 ms |
1880 KB |
Output is correct |
7 |
Correct |
1086 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
15 ms |
13104 KB |
Output is correct |
6 |
Correct |
355 ms |
44612 KB |
Output is correct |
7 |
Correct |
345 ms |
44860 KB |
Output is correct |
8 |
Correct |
220 ms |
20844 KB |
Output is correct |
9 |
Correct |
2749 ms |
36980 KB |
Output is correct |
10 |
Correct |
726 ms |
32976 KB |
Output is correct |
11 |
Execution timed out |
3044 ms |
58620 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |