이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1e9+7;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t z;
const int mxn = 2e5+5;
#include "meetings.h"
/*
void bridge(int a, int b){
cout<<"bridge : "<<a<<"-"<<b<<endl;
}
int Query(int a, int b, int c){
cout<<a<<' '<<b<<' '<<c<<endl;
int d;
cin >> d;
return d;
}*/
int cpr[mxn];
vector<int> Sort(vector<int> v, int l, int r){
if((int)v.size() <= 1) return v;
int pivot = v[_rand()%(int)v.size()];
vector<int> L;
vector<int> R;
for(auto u : v){
if(u == pivot) continue;
int q = Query(l, u, pivot);
if(q == u){
L.pb(u);
}
else{
R.pb(u);
}
}
L = Sort(L, l, pivot);
R = Sort(R, pivot, r);
v.clear();
for(auto u : L) v.pb(u);
v.pb(pivot);
for(auto u : R) v.pb(u);
return v;
}
void bridge(int a, int b){
Bridge(min(a,b), max(a,b));
}
void solve(vector<int> v){
sort(all(v));
v.erase(unique(all(v)), v.end());
int m = (int)v.size();
if(m <= 1) return;
if(m == 2){
bridge(v[0], v[1]);
return;
}
int a = _rand()%m;
int b = _rand()%(m-1);
if(b >= a) ++b;
a = v[a];
b = v[b];
vector<int> g[m];
fr(i, 0, m){
cpr[v[i]] = i;
g[i].pb(v[i]);
}
vector<int> diam;
fr(i, 0, m){
if(v[i] == a || v[i] == b) continue;
int q = Query(a, b, v[i]);
g[cpr[q]].pb(v[i]);
if(q != a && q != b) diam.pb(q);
}
sort(all(diam));
diam.erase(unique(all(diam)), diam.end());
diam = Sort(diam, a, b);
diam.insert(diam.begin(), a);
diam.pb(b);
fr(i, 0, (int)diam.size()-1){
bridge(diam[i], diam[i+1]);
}
fr(i, 0, m){
solve(g[i]);
}
}
void Solve(int N){
vector<int> v;
fr(i, 0, N) v.pb(i);
solve(v);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |