#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct DSU{
int path[111];
void init(int n){for (int i=1;i<=n;i++) path[i] = i;}
int find(int s){
if (s==path[s]) return s;
return path[s] = find(path[s]);
}
void merge(int s, int v){
s = find(s), v = find(v);
if (s==v) return;
path[s] = v;
}
}dsu;
int A[111], B[111];
int Q(vector<int>::iterator a1, vector<int>::iterator a2, vector<int>::iterator b1, vector<int>::iterator b2){
int sa = a2 - a1, sb = b2 - b1;
for (int i=0;i<sa;i++) A[i] = *(a1+i);
for (int i=0;i<sb;i++) B[i] = *(b1+i);
return query(sa, sb, A, B);
}
vector<int> _A, _B, V[111];
int myquery(int mx, int k, bool flag = 0){
_A.clear(), _B.clear();
for (int i=0;i<mx;i++){
if (i&(1<<k)){
for (auto &x:V[i]) _B.push_back(x);
}
else{
for (auto &x:V[i]) _A.push_back(x);
}
}
if (flag) return 1;
return Q(_A.begin(), _A.end(), _B.begin(), _B.end());
}
int _search(vector<int> A, vector<int> B){
int l = 0, r = (int)A.size()-2, ans = (int)A.size()-1;
while(l<=r){
int m = (l+r)>>1;
if (Q(A.begin(), A.begin()+m+1, B.begin(), B.end())) ans = m, r = m-1;
else l = m+1;
}
return A[ans];
}
void run(int n){
dsu.init(n);
for (int z=0;z<n-1;z++){
vector<int> idx;
for (int i=1;i<=n;i++) idx.push_back(dsu.find(i));
sort(idx.begin(), idx.end());
idx.erase(unique(idx.begin(), idx.end()), idx.end());
for (int i=0;i<=n;i++) V[i].clear();
for (int i=1;i<=n;i++) V[lower_bound(idx.begin(), idx.end(), dsu.find(i)) - idx.begin()].push_back(i);
int mx = idx.size();
vector<int> K;
for (int k=0;(1<<k)<mx;k++) K.push_back(k);
int k;
for (auto &kk:K){
k = kk;
if (kk==K.back()) {myquery(mx, k, 1); break;}
if (myquery(mx, k)) break;
}
int x = _search(_A, _B);
int y = _search(_B, {x});
setRoad(x, y);
dsu.merge(x, y);
}
}
//int main(){}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Ok! 93 queries used. |
2 |
Correct |
5 ms |
468 KB |
Ok! 100 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
496 KB |
Ok! 540 queries used. |
2 |
Correct |
35 ms |
476 KB |
Ok! 640 queries used. |
3 |
Correct |
35 ms |
492 KB |
Ok! 648 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
496 KB |
Ok! 1451 queries used. |
2 |
Correct |
119 ms |
500 KB |
Ok! 1605 queries used. |
3 |
Correct |
118 ms |
468 KB |
Ok! 1573 queries used. |
4 |
Correct |
118 ms |
496 KB |
Ok! 1514 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
500 KB |
Ok! 1544 queries used. |
2 |
Correct |
119 ms |
484 KB |
Ok! 1477 queries used. |
3 |
Correct |
113 ms |
484 KB |
Ok! 1535 queries used. |
4 |
Correct |
113 ms |
500 KB |
Ok! 1531 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
512 KB |
Ok! 1536 queries used. |
2 |
Correct |
112 ms |
488 KB |
Ok! 1535 queries used. |
3 |
Correct |
110 ms |
716 KB |
Ok! 1535 queries used. |
4 |
Correct |
115 ms |
496 KB |
Ok! 1592 queries used. |
5 |
Correct |
107 ms |
492 KB |
Ok! 1493 queries used. |
6 |
Correct |
128 ms |
500 KB |
Ok! 1561 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
496 KB |
Ok! 1535 queries used. |
2 |
Correct |
114 ms |
496 KB |
Ok! 1605 queries used. |