#include "bits/stdc++.h"
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif
#define ar array
const int N = 1e5 + 5;
const int C = 50;
vector<ar<int, 2>> edges[N];
vector<set<ar<int, 2>>> vals[N];
int h[N], n;
void init(int N, int D, int H[]) {
n = N;
for(int i=0;i<N;i++){
h[i] = H[i];
}
}
void curseChanges(int U, int A[], int B[]) {
for(int i=0;i<U;i++){
edges[A[i]].push_back({i + 1, B[i]});
edges[B[i]].push_back({i + 1, A[i]});
}
for(int i=0;i<n;i++){
set<ar<int, 2>> ss;
for(int j=0;j<(int)edges[i].size();j++){
if(j % C == 0){
vals[i].push_back(ss);
}
if(ss.count({h[edges[i][j][1]], edges[i][j][1]})){
ss.erase({h[edges[i][j][1]], edges[i][j][1]});
} else {
ss.insert({h[edges[i][j][1]], edges[i][j][1]});
}
}
}
}
void get(int a, int t, set<ar<int, 2>>& res){
int j = lower_bound(edges[a].begin(), edges[a].end(), (ar<int, 2>){t + 1, -1}) - edges[a].begin();
if(!j) return;
j--;
res = vals[a][j/C];
for(int k=(j/C) * C;k<(int)edges[a].size() && edges[a][k][0]<=t;k++){
if(res.count({h[edges[a][k][1]], edges[a][k][1]})){
res.erase({h[edges[a][k][1]], edges[a][k][1]});
} else {
res.insert({h[edges[a][k][1]], edges[a][k][1]});
}
}
//~ for(auto x : res) cout<<x[0]<<" ";
//~ cout<<"\n";
return;
}
set<ar<int, 2>> a, b;
int question(int x, int y, int v) {
a.clear(), b.clear();
get(x, v, a), get(y, v, b);
auto lx = a.begin(), rx = b.begin();
int last = -1e9, f = -1, res = 1e9;
while(lx != a.end() || rx != b.end()){
if(f == 0 && rx != b.end()) res = min(res, (*rx)[0] - last);
if(f == 1 && lx != a.end()) res = min(res, (*lx)[0] - last);
if(lx != a.end() && rx != b.end()){
if(*lx <= *rx) last = (*lx)[0], f = 0, lx++;
else last = (*rx)[0], f = 1, rx++;
} else break;
}
return res;
}
/*
6 5 11 4
2 42 1000 54 68 234
0 1
2 0
3 4
3 5
3 5
1 3
5 3
0 5
3 0
1 3
3 5
0 3 4 26
3 0 8 0
0 5 5 1000000000
3 0 11 14
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5072 KB |
Output is correct |
2 |
Correct |
4 ms |
5072 KB |
Output is correct |
3 |
Correct |
4 ms |
5072 KB |
Output is correct |
4 |
Correct |
16 ms |
5960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
235 ms |
19460 KB |
Output is correct |
2 |
Correct |
198 ms |
19512 KB |
Output is correct |
3 |
Correct |
455 ms |
14760 KB |
Output is correct |
4 |
Correct |
1823 ms |
57888 KB |
Output is correct |
5 |
Correct |
690 ms |
13412 KB |
Output is correct |
6 |
Correct |
2945 ms |
85600 KB |
Output is correct |
7 |
Correct |
874 ms |
25128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
237 ms |
19508 KB |
Output is correct |
2 |
Correct |
2542 ms |
89588 KB |
Output is correct |
3 |
Correct |
1596 ms |
51784 KB |
Output is correct |
4 |
Correct |
2603 ms |
85064 KB |
Output is correct |
5 |
Correct |
372 ms |
23468 KB |
Output is correct |
6 |
Correct |
2836 ms |
85248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
5968 KB |
Output is correct |
2 |
Correct |
235 ms |
5464 KB |
Output is correct |
3 |
Correct |
403 ms |
5584 KB |
Output is correct |
4 |
Correct |
1086 ms |
7208 KB |
Output is correct |
5 |
Correct |
978 ms |
6864 KB |
Output is correct |
6 |
Correct |
191 ms |
5328 KB |
Output is correct |
7 |
Correct |
944 ms |
6568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
4 ms |
5072 KB |
Output is correct |
3 |
Correct |
4 ms |
5072 KB |
Output is correct |
4 |
Correct |
4 ms |
5072 KB |
Output is correct |
5 |
Correct |
16 ms |
5960 KB |
Output is correct |
6 |
Correct |
235 ms |
19460 KB |
Output is correct |
7 |
Correct |
198 ms |
19512 KB |
Output is correct |
8 |
Correct |
455 ms |
14760 KB |
Output is correct |
9 |
Correct |
1823 ms |
57888 KB |
Output is correct |
10 |
Correct |
690 ms |
13412 KB |
Output is correct |
11 |
Correct |
2945 ms |
85600 KB |
Output is correct |
12 |
Correct |
874 ms |
25128 KB |
Output is correct |
13 |
Correct |
237 ms |
19508 KB |
Output is correct |
14 |
Correct |
2542 ms |
89588 KB |
Output is correct |
15 |
Correct |
1596 ms |
51784 KB |
Output is correct |
16 |
Correct |
2603 ms |
85064 KB |
Output is correct |
17 |
Correct |
372 ms |
23468 KB |
Output is correct |
18 |
Correct |
2836 ms |
85248 KB |
Output is correct |
19 |
Correct |
45 ms |
5968 KB |
Output is correct |
20 |
Correct |
235 ms |
5464 KB |
Output is correct |
21 |
Correct |
403 ms |
5584 KB |
Output is correct |
22 |
Correct |
1086 ms |
7208 KB |
Output is correct |
23 |
Correct |
978 ms |
6864 KB |
Output is correct |
24 |
Correct |
191 ms |
5328 KB |
Output is correct |
25 |
Correct |
944 ms |
6568 KB |
Output is correct |
26 |
Correct |
1039 ms |
37912 KB |
Output is correct |
27 |
Correct |
1528 ms |
51760 KB |
Output is correct |
28 |
Correct |
1485 ms |
47100 KB |
Output is correct |
29 |
Correct |
1649 ms |
58184 KB |
Output is correct |
30 |
Correct |
2789 ms |
85408 KB |
Output is correct |
31 |
Correct |
2481 ms |
92420 KB |
Output is correct |
32 |
Correct |
2554 ms |
85432 KB |
Output is correct |