#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 = 5;
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;
}
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()) {
| ~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
13 ms |
13116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
45800 KB |
Output is correct |
2 |
Correct |
353 ms |
45976 KB |
Output is correct |
3 |
Correct |
204 ms |
24000 KB |
Output is correct |
4 |
Correct |
2293 ms |
59428 KB |
Output is correct |
5 |
Correct |
671 ms |
37624 KB |
Output is correct |
6 |
Execution timed out |
3052 ms |
87256 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
370 ms |
46016 KB |
Output is correct |
2 |
Execution timed out |
3013 ms |
86204 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
3672 KB |
Output is correct |
2 |
Correct |
103 ms |
2412 KB |
Output is correct |
3 |
Correct |
165 ms |
2284 KB |
Output is correct |
4 |
Correct |
1094 ms |
4440 KB |
Output is correct |
5 |
Correct |
1370 ms |
4172 KB |
Output is correct |
6 |
Correct |
141 ms |
2136 KB |
Output is correct |
7 |
Correct |
919 ms |
3232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
13 ms |
13116 KB |
Output is correct |
6 |
Correct |
338 ms |
45800 KB |
Output is correct |
7 |
Correct |
353 ms |
45976 KB |
Output is correct |
8 |
Correct |
204 ms |
24000 KB |
Output is correct |
9 |
Correct |
2293 ms |
59428 KB |
Output is correct |
10 |
Correct |
671 ms |
37624 KB |
Output is correct |
11 |
Execution timed out |
3052 ms |
87256 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |