#include "bits/stdc++.h"
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif
#define ar array
#define ff first
#define ss second
const int N = 1e5 + 5;
const int C = 1;
vector<pair<int, int>> edges[N];
vector<set<pair<int, int>>> 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<pair<int, int>> ss;
int v = 0;
for(int j=0;j<(int)edges[i].size();j++){
if(j == v){ v += C;
vals[i].push_back(ss);
}
if(ss.count({h[edges[i][j].ss], edges[i][j].ss})){
ss.erase({h[edges[i][j].ss], edges[i][j].ss});
} else {
ss.insert({h[edges[i][j].ss], edges[i][j].ss});
}
}
}
}
void get(int a, int t, set<pair<int, int>>& res){
int j = lower_bound(edges[a].begin(), edges[a].end(), make_pair(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].ff<=t;k++){
if(res.count({h[edges[a][k].ss], edges[a][k].ss})){
res.erase({h[edges[a][k].ss], edges[a][k].ss});
} else {
res.insert({h[edges[a][k].ss], edges[a][k].ss});
}
}
return;
}
set<pair<int, int>> 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).ff - last);
if(f == 1 && lx != a.end()) res = min(res, (*lx).ff - last);
if(lx != a.end() && rx != b.end()){
if(*lx <= *rx) last = (*lx).ff, f = 0, lx++;
else last = (*rx).ff, 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 |
6 ms |
5200 KB |
Output is correct |
2 |
Correct |
5 ms |
5200 KB |
Output is correct |
3 |
Correct |
7 ms |
5200 KB |
Output is correct |
4 |
Correct |
18 ms |
5904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
306 ms |
76192 KB |
Output is correct |
2 |
Correct |
309 ms |
76284 KB |
Output is correct |
3 |
Correct |
488 ms |
208320 KB |
Output is correct |
4 |
Runtime error |
279 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
325 ms |
76412 KB |
Output is correct |
2 |
Runtime error |
322 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
7596 KB |
Output is correct |
2 |
Correct |
117 ms |
14776 KB |
Output is correct |
3 |
Correct |
170 ms |
15568 KB |
Output is correct |
4 |
Correct |
936 ms |
69516 KB |
Output is correct |
5 |
Correct |
903 ms |
52796 KB |
Output is correct |
6 |
Correct |
150 ms |
15824 KB |
Output is correct |
7 |
Correct |
774 ms |
60284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
6 ms |
5200 KB |
Output is correct |
3 |
Correct |
5 ms |
5200 KB |
Output is correct |
4 |
Correct |
7 ms |
5200 KB |
Output is correct |
5 |
Correct |
18 ms |
5904 KB |
Output is correct |
6 |
Correct |
306 ms |
76192 KB |
Output is correct |
7 |
Correct |
309 ms |
76284 KB |
Output is correct |
8 |
Correct |
488 ms |
208320 KB |
Output is correct |
9 |
Runtime error |
279 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |