#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
// #define int long long
#define ll long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 2e5+10;
int n, a[maxn], idord[maxn];
vector<pair<int,int>> ord;
vector<pair<int,int>> g[maxn];
vector<pair<int,vector<int>>> frds[maxn];
const int BC = 8;
void init(int N, int D, int H[]) {
n = N;
for(int i = 0; i < n; i++) {
ord.pb(mp(H[i],i));
}
sort(all(ord));
for(int i = 0; i < n; i++) {
idord[ord[i].sc] = i;
a[i] = ord[i].fr;
}
}
void curseChanges(int U, int A[], int B[]) {
for(int i = 0; i < U; i++) {
int u = idord[A[i]];
int v = idord[B[i]];
g[u].pb(mp(i+1,v));
g[v].pb(mp(i+1,u));
}
for(int i = 0; i < n; i++) {
set<int> st;
int cnt = 0;
frds[i].pb(mp(0,vector<int>{}));
for(auto X : g[i]) {
int j = X.sc;
int id = X.fr;
if(st.count(j)) st.erase(j);
else st.insert(j);
if(++cnt == BC || g[i].back().fr == id) {
frds[i].pb(mp(id,vector<int>{}));
for(auto x : st) {
frds[i].back().sc.pb(x);
}
cnt = 0;
}
}
frds[i].pb(mp(U+1,vector<int>{}));
g[i].pb(mp(U+1,-1));
// cout << i << " " << a[i] << endl;
// for(auto x : frds[i]) {
// cout << " " << x.fr << endl;
// }
}
}
int question(int x, int y, int v) {
x = idord[x];
y = idord[y];
vector<int> vcx, vcx0, vcx1;
auto itfrx = prev(lower_bound(all(frds[x]),mp(v+1,vector<int>{})));
vcx0 = itfrx->sc;
// vcx = vcx0;
set<int> stx;
for(auto it = lower_bound(all(g[x]),mp(itfrx->fr+1,-1)); it->fr <= v; it++) {
int i = it->sc;
if(stx.count(i)) stx.erase(i);
else stx.insert(i);
}
// assert(stx.size() == 0);
for(auto i : stx) vcx1.pb(i);
int i0 = 0;
int i1 = 0;
while(i0 != vcx0.size() && i1 != vcx1.size()) {
if(vcx0[i0] < vcx1[i1]) {
vcx.pb(vcx0[i0]);
i0++;
}
else if(vcx0[i0] > vcx1[i1]) {
vcx.pb(vcx1[i1]);
i1++;
}
else {
i0++;
i1++;
}
}
while(i0 != vcx0.size()) {
vcx.pb(vcx0[i0]);
i0++;
}
while(i1 != vcx1.size()) {
vcx.pb(vcx1[i1]);
i1++;
}
// cout << x << " " << " x " << prev(lower_bound(all(frds[x]),mp(v+1,vector<int>{})))->fr << endl;
vector<int> vcy, vcy0, vcy1;
auto itfry = prev(lower_bound(all(frds[y]),mp(v+1,vector<int>{})));
vcy0 = itfry->sc;
// vcy = vcy0;
set<int> sty;
for(auto it = lower_bound(all(g[y]),mp(itfry->fr+1,-1)); it->fr <= v; it++) {
int i = it->sc;
if(sty.count(i)) sty.erase(i);
else sty.insert(i);
}
for(auto i : sty) vcy1.pb(i);
int j0 = 0;
int j1 = 0;
while(j0 != vcy0.size() && j1 != vcy1.size()) {
if(vcy0[j0] < vcy1[j1]) {
vcy.pb(vcy0[j0]);
j0++;
}
else if(vcy0[j0] > vcy1[j1]) {
vcy.pb(vcy1[j1]);
j1++;
}
else {
j0++;
j1++;
}
}
while(j0 != vcy0.size()) {
vcy.pb(vcy0[j0]);
j0++;
}
while(j1 != vcy1.size()) {
vcy.pb(vcy1[j1]);
j1++;
}
// cout << " y " << prev(lower_bound(all(frds[y]),mp(v+1,vector<int>{})))->fr << endl;
if(vcx.size() == 0) return 1000000000;
if(vcy.size() == 0) return 1000000000;
int i = 0;
int j = 0;
int ans = inf1;
while(i != vcx.size() && j != vcy.size()) {
ans = min(ans, abs(a[vcx[i]]-a[vcy[j]]));
if(a[vcx[i]] < a[vcy[j]]) {
//increase i
i++;
}
else {
j++;
}
}
return ans;
}
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:91:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | while(i0 != vcx0.size() && i1 != vcx1.size()) {
| ~~~^~~~~~~~~~~~~~
potion.cpp:91:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | while(i0 != vcx0.size() && i1 != vcx1.size()) {
| ~~~^~~~~~~~~~~~~~
potion.cpp:105:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | while(i0 != vcx0.size()) {
| ~~~^~~~~~~~~~~~~~
potion.cpp:109:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | while(i1 != vcx1.size()) {
| ~~~^~~~~~~~~~~~~~
potion.cpp:128:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
128 | while(j0 != vcy0.size() && j1 != vcy1.size()) {
| ~~~^~~~~~~~~~~~~~
potion.cpp:128:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
128 | while(j0 != vcy0.size() && j1 != vcy1.size()) {
| ~~~^~~~~~~~~~~~~~
potion.cpp:142:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
142 | while(j0 != vcy0.size()) {
| ~~~^~~~~~~~~~~~~~
potion.cpp:146:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
146 | while(j1 != vcy1.size()) {
| ~~~^~~~~~~~~~~~~~
potion.cpp:158:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
158 | while(i != vcx.size() && j != vcy.size()) {
| ~~^~~~~~~~~~~~~
potion.cpp:158:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
158 | while(i != vcx.size() && j != vcy.size()) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9904 KB |
Output is correct |
2 |
Correct |
7 ms |
9936 KB |
Output is correct |
3 |
Correct |
7 ms |
9984 KB |
Output is correct |
4 |
Correct |
45 ms |
22724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
276 ms |
37792 KB |
Output is correct |
2 |
Correct |
286 ms |
37848 KB |
Output is correct |
3 |
Correct |
215 ms |
32392 KB |
Output is correct |
4 |
Correct |
532 ms |
54720 KB |
Output is correct |
5 |
Correct |
264 ms |
27288 KB |
Output is correct |
6 |
Correct |
866 ms |
78288 KB |
Output is correct |
7 |
Correct |
347 ms |
41364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
307 ms |
37844 KB |
Output is correct |
2 |
Correct |
653 ms |
74956 KB |
Output is correct |
3 |
Correct |
509 ms |
57584 KB |
Output is correct |
4 |
Correct |
630 ms |
78348 KB |
Output is correct |
5 |
Correct |
314 ms |
40884 KB |
Output is correct |
6 |
Correct |
671 ms |
78440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
11984 KB |
Output is correct |
2 |
Correct |
102 ms |
11600 KB |
Output is correct |
3 |
Correct |
118 ms |
11548 KB |
Output is correct |
4 |
Correct |
239 ms |
12744 KB |
Output is correct |
5 |
Correct |
239 ms |
12948 KB |
Output is correct |
6 |
Correct |
115 ms |
10576 KB |
Output is correct |
7 |
Correct |
238 ms |
12244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9680 KB |
Output is correct |
2 |
Correct |
7 ms |
9904 KB |
Output is correct |
3 |
Correct |
7 ms |
9936 KB |
Output is correct |
4 |
Correct |
7 ms |
9984 KB |
Output is correct |
5 |
Correct |
45 ms |
22724 KB |
Output is correct |
6 |
Correct |
276 ms |
37792 KB |
Output is correct |
7 |
Correct |
286 ms |
37848 KB |
Output is correct |
8 |
Correct |
215 ms |
32392 KB |
Output is correct |
9 |
Correct |
532 ms |
54720 KB |
Output is correct |
10 |
Correct |
264 ms |
27288 KB |
Output is correct |
11 |
Correct |
866 ms |
78288 KB |
Output is correct |
12 |
Correct |
347 ms |
41364 KB |
Output is correct |
13 |
Correct |
307 ms |
37844 KB |
Output is correct |
14 |
Correct |
653 ms |
74956 KB |
Output is correct |
15 |
Correct |
509 ms |
57584 KB |
Output is correct |
16 |
Correct |
630 ms |
78348 KB |
Output is correct |
17 |
Correct |
314 ms |
40884 KB |
Output is correct |
18 |
Correct |
671 ms |
78440 KB |
Output is correct |
19 |
Correct |
72 ms |
11984 KB |
Output is correct |
20 |
Correct |
102 ms |
11600 KB |
Output is correct |
21 |
Correct |
118 ms |
11548 KB |
Output is correct |
22 |
Correct |
239 ms |
12744 KB |
Output is correct |
23 |
Correct |
239 ms |
12948 KB |
Output is correct |
24 |
Correct |
115 ms |
10576 KB |
Output is correct |
25 |
Correct |
238 ms |
12244 KB |
Output is correct |
26 |
Correct |
415 ms |
48696 KB |
Output is correct |
27 |
Correct |
580 ms |
57668 KB |
Output is correct |
28 |
Correct |
616 ms |
57772 KB |
Output is correct |
29 |
Correct |
560 ms |
54680 KB |
Output is correct |
30 |
Correct |
844 ms |
78424 KB |
Output is correct |
31 |
Correct |
806 ms |
75544 KB |
Output is correct |
32 |
Correct |
810 ms |
78380 KB |
Output is correct |