#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
const int MN = 100000;
int n;
int H0[MN];
vector<pair<int, int> > Op[MN];
vi SnapId[MN];
vi Mare[400000];
int pma = 0;
void init(int N, int D, int H[]) {
n = N;
for(int i = 0; i < n; ++i)
H0[i] = H[i];
}
int rad = 30;
void curseChanges(int U, int A[], int B[]) {
for(int i = 0; i < U; ++i) {
Op[A[i]].push_back({i + 1, B[i]});
Op[B[i]].push_back({i + 1, A[i]});
}
set<int> S;
for(int i = 0; i < n; ++i) {
S.clear();
SnapId[i].push_back(pma);
++pma;
for(int j = 0; j < Op[i].size(); ++j) {
if(j % rad == 0 && j) {
SnapId[i].push_back(pma);
Mare[pma].reserve(S.size());
for(auto it : S) Mare[pma].push_back(it);
++pma;
}
auto [t, v] = Op[i][j];
if(S.count(v)) S.erase(v);
else S.insert(v);
}
}
}
const int INF = 1e9;
set<int> get(int x, int v) {
int st = 0, dr = int(Op[x].size()) - 1, mij;
if(Op[x].empty() || Op[x][0].first > v) return set<int>();
while(st < dr) {
mij = (st + dr + 1) / 2;
if(Op[x][mij].first > v) dr = mij - 1; // e ok asa?
else st = mij;
}
set<int> S;
for(auto it : Mare[SnapId[x][st / rad]])
S.insert(it);
for(int i = st / rad * rad; i <= st; ++i) {
auto [t, v] = Op[x][i];
if(S.count(v)) S.erase(v);
else S.insert(v);
}
return S;
}
int question(int x, int y, int v) {
auto VecX = get(x, v), VecY = get(y, v);
vi VA, VB;
for(auto it : VecX) VA.push_back(H0[it]);
for(auto it : VecY) VB.push_back(H0[it]);
sort(VA.begin(), VA.end());
sort(VB.begin(), VB.end());
int pa = 0, pb = 0;
int re = INF;
while(pa < VA.size() && pb < VB.size()) {
re = min(re, abs(VA[pa] - VB[pb]));
if(VA[pa] < VB[pb]) ++pa;
else ++pb;
}
return re;
}
Compilation message
potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:34:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int j = 0; j < Op[i].size(); ++j) {
| ~~^~~~~~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:77:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | while(pa < VA.size() && pb < VB.size()) {
| ~~~^~~~~~~~~~~
potion.cpp:77:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | while(pa < VA.size() && pb < VB.size()) {
| ~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14424 KB |
Output is correct |
2 |
Correct |
4 ms |
14512 KB |
Output is correct |
3 |
Correct |
6 ms |
14424 KB |
Output is correct |
4 |
Correct |
18 ms |
19004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
26216 KB |
Output is correct |
2 |
Correct |
167 ms |
25892 KB |
Output is correct |
3 |
Correct |
245 ms |
23788 KB |
Output is correct |
4 |
Correct |
2067 ms |
27224 KB |
Output is correct |
5 |
Correct |
454 ms |
22776 KB |
Output is correct |
6 |
Execution timed out |
3024 ms |
34608 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
25944 KB |
Output is correct |
2 |
Correct |
2636 ms |
34804 KB |
Output is correct |
3 |
Correct |
1357 ms |
29912 KB |
Output is correct |
4 |
Correct |
2724 ms |
34728 KB |
Output is correct |
5 |
Correct |
349 ms |
27408 KB |
Output is correct |
6 |
Execution timed out |
3079 ms |
34624 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
15448 KB |
Output is correct |
2 |
Correct |
151 ms |
15192 KB |
Output is correct |
3 |
Correct |
262 ms |
15192 KB |
Output is correct |
4 |
Correct |
1269 ms |
15544 KB |
Output is correct |
5 |
Correct |
1306 ms |
15448 KB |
Output is correct |
6 |
Correct |
161 ms |
15192 KB |
Output is correct |
7 |
Correct |
1010 ms |
15580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14424 KB |
Output is correct |
2 |
Correct |
4 ms |
14424 KB |
Output is correct |
3 |
Correct |
4 ms |
14512 KB |
Output is correct |
4 |
Correct |
6 ms |
14424 KB |
Output is correct |
5 |
Correct |
18 ms |
19004 KB |
Output is correct |
6 |
Correct |
180 ms |
26216 KB |
Output is correct |
7 |
Correct |
167 ms |
25892 KB |
Output is correct |
8 |
Correct |
245 ms |
23788 KB |
Output is correct |
9 |
Correct |
2067 ms |
27224 KB |
Output is correct |
10 |
Correct |
454 ms |
22776 KB |
Output is correct |
11 |
Execution timed out |
3024 ms |
34608 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |