# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
922389 | 1075508020060209tc | Meetings (JOI19_meetings) | C++14 | 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.
#pragma GCC optimize("O3")
#include "meetings.h"
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define X first
#define Y second
#define SZ(x) (int)(x).size()
unsigned seed=12345;
long long rnd(){
seed=seed^(seed<<7);
seed=seed^(seed>>4);
seed=seed^(seed>>3);
return seed;
}
map<vector<int>,int>mp;
int n;
int query(int a,int b,int c){
vector<int>vc={a,b,c};
sort(vc.begin(),vc.end());
if(vc[0]==vc[1]){return vc[0];}
if(vc[1]==vc[2]){return vc[2];}
if(mp[vc]){return mp[vc];}
mp[vc]=Query(vc[0]-1,vc[1]-1,vc[2]-1)+1;
return mp[vc];
}
set<pair<int,int>>ans;
int finmid(vector<int>&vc){
int a=rnd()%vc.size();
int b=rnd()%vc.size();
if(b==a){b++;b%=vc.size();}
int c=rnd()%vc.size();
if(c==a){
c++;c%=vc.size();
}
if(c==b){
c++;c%=vc.size();
}
return query(vc[0],vc[1],vc[2]);
}
void slv(vector<int>vc){
if(vc.size()==1){return;}
if(vc.size()==2){
ans.insert({min(vc[0],vc[1]),max(vc[0],vc[1])});
return;
}
random_shuffle(vc.begin(),vc.end(),rnd);
random_shuffle(vc.begin(),vc.end());
vector<int>vcb;vector<int>vca;
int md=vc[0];
int w=vc[1];
md=query(vc[0],vc[1],vc[2]);
for(int i=0;i<vc.size();i++){
if(vc[i]==md){
swap(vc[i],vc[0]);
}
}
w=vc[1];
set<int>st;
st.insert(w);
for(int i=2;i<vc.size();i++){
int v=vc[i];
if(v==w){
st.insert(v);
continue;
}
int vv=query(md,w,v);
if(vv==md){continue;}
st.insert(vc[i]);
w=vv;
}
for(int i=0;i<vc.size();i++){
if(st.find(vc[i])!=st.end()){
vca.push_back(vc[i]);
}else{
vcb.push_back(vc[i]);
}
}
ans.insert({min(md,w),max(md,w)});
slv(vca);
slv(vcb);
}
void Solve(int N){
n=N;
vector<int>vc;
for(int i=1;i<=n;i++){
vc.push_back(i);
}
slv(vc);
for(auto it=ans.begin();it!=ans.end();it++){
Bridge((*it).first-1, (*it).second-1);
}
}