# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1183402 | mertbbm | ICC (CEOI16_icc) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
//#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
struct DSU{
vector<int>e;
void init(int n){
e=vector<int>(n,-1);
}
int get(int x){
return e[x]<0?x:e[x]=get(e[x]);
}
bool unite(int x, int y){
x=get(x); y=get(y);
if(x==y) return 0;
if(e[x]>e[y]) swap(x,y);
e[x]+=e[y];
e[y]=x;
return 1;
}
};
//int query(int a, int b, int arr[], int arr2[]){
//for(int x=0;x<a;x++) cout << arr[x] << " ";
//cout << "\n";
//for(int x=0;x<b;x++) cout << arr2[x] << " ";
//cout << "\n";
//int ret;
//cin >> ret;
//cout << "\n";
//return ret;
//}
//void setRoad(int a, int b){
//show2(edge,a,edge,b);
//}
void run(int n){
int n;
//cin >> n;
DSU dsu;
dsu.init(n+5);
vector<int>bit={2,4,8,16,32,64,128};
for(int x=0;x<n-1;x++){
int a[105];
int b[105];
int ptr=0;
int ptr2=0;
vector<int>nodes;
for(int y=1;y<=n;y++){
nodes.push_back(y-1);
}
int need=lower_bound(bit.begin(),bit.end(),nodes.size())-bit.begin();
for(int y=0;y<=need;y++){
ptr=0;
ptr2=0;
for(auto it:nodes){
if(it&(1<<y)){
a[ptr++]=it+1;
}
else{
b[ptr2++]=it+1;
}
}
if(query(ptr,ptr2,a,b)){
break;
}
}
//decomp
while(ptr>1||ptr2>1){
//2 queries
int a1[105];
int b1[105];
int a2[105];
int b2[105];
int a11=0;
int a22=0;
int b11=0;
int b22=0;
for(int y=0;y<ptr;y++){
if(y%2){
//a1.push_back(a[y]);
a1[a11++]=a[y];
}
else{
//a2.push_back(a[y]);
a2[a22++]=a[y];
}
}
for(int y=0;y<ptr2;y++){
if(y%2){
//b1.push_back(b[y]);
b1[b11++]=b[y];
}
else{
//b2.push_back(b[y]);
b2[b22++]=b[y];
}
}
bool hold=query(a11,ptr2,a1,b);
if(hold){
hold=query(a11,b11,a1,b1);
for(int i=0;i<a11;i++){
a[i]=a1[i];
}
ptr=a11;
if(hold){
for(int i=0;i<b11;i++){
b[i]=b1[i];
}
ptr2=b11;
}
else{
for(int i=0;i<b22;i++){
b[i]=b2[i];
}
ptr2=b22;
}
}
else{
for(int i=0;i<a22;i++){
a[i]=a2[i];
}
ptr=a22;
hold=query(a22,b11,a2,b1);
if(hold){
for(int i=0;i<b11;i++){
b[i]=b1[i];
}
ptr2=b11;
}
else{
for(int i=0;i<b22;i++){
b[i]=b2[i];
}
ptr2=b22;
}
}
}
dsu.unite(a[0],b[0]);
setRoad(a[0],b[0]);
}
}