# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
988278 | binminh01 | ICC (CEOI16_icc) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
void run(int n) {
dsu u; u.init(n);
int l = Log2(n);
For(_,1,n){
For(i,0,l){
vi a, b;
For(j,0,n){
int w = u.get(j);
if ((w >> i) & 1) a.pb(j);
else b.pb(j);
}
if (query(a, b)) {
shuffle(all(a), mt); shuffle(all(b), mt);
int l = 0, r = sz(a) - 1;
while (l < r) {
int m = (l + r) >> 1;
if (query(vi(a.begin() + l, a.begin() + m + 1), b)) r = m;
else l = m + 1;
}
int x = l;
l = 0; r = sz(b) - 1;
while (l < r) {
int m = (l + r) >> 1;
if (query(vi{a[x]}, vi(b.begin() + l, b.begin() + m + 1))) r = m;
else l = m + 1;
}
int y = l;
u.merge(a[x], b[y]);
setRoad(a[x] + 1, b[y] + 1);
break;
}
}
}
}