Submission #250768

#TimeUsernameProblemLanguageResultExecution timeMemory
250768ryanseeHighway Tolls (IOI18_highway)C++14
12 / 100
270 ms13888 KiB
#include "highway.h"

#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (100006)
vector<pi> v[MAXN];
ll Q;
ll askk(vector<int> W){
	assert(++Q <= 60);
	return ask(W);
}
void find_pair(int n, std::vector<int> U, std::vector<int> V, int A, int B) {
	FOR(i,0,n-2){
		v[U[i]].eb(V[i], i), v[V[i]].eb(U[i], i);
	}
	vector<int> W(n-1, 0), pe(n, 0), depth(n, 0), stt(n, 0), enn(n, 0);
	ll init = askk(W), len = init / A, co=0;
	function<void(ll,ll)>dfs=[&](ll x,ll p){
		stt[x]=co++;
		for(auto i:v[x])if(i.f^p)depth[i.f]=depth[x]+1, pe[i.f]=i.s, dfs(i.f,x);
		enn[x]=co-1;
	};
	dfs(0,0);
	auto bstar1=[&](ll x){
		FOR(i,1,n-1) if(depth[i]>=x) W[pe[i]]=1; else W[pe[i]]=0;
		return askk(W);
	};
	ll st = 0, en = n;
	while(en-st>1){
		ll mid=(st+en)>>1;
		if(bstar1(mid)-init) st=mid;
		else en=mid;
	}assert(st);
	auto bstar2=[&](ll x,ll z,ll y){
		FOR(i,0,n-2)W[i]=0;
		FOR(i,y,n-1) if(depth[i]==x||depth[i]==z) W[pe[i]]=1; else W[pe[i]]=0;
		return askk(W);
	};
	ll o = st;
	// cerr<<"one depth: "<<o<<'\n';
	st = -1, en = o;
	while(en-st>1){
		ll mid=(st+en)>>1;
		if(bstar1(mid)-init == (o-mid+1) * (B-A))en=mid;
		else st=mid;
	}
	// st is depth of other
	bool gay = 0;
	if(o-st >= len){
		st = o - len;
		gay = 1;
	}
	ll o2=st;
	// cerr<<"two depth: "<<o2<<'\n';
	st=1, en=n;
	while(en-st>1){
		ll mid=(st+en)>>1;
		if(bstar2(o,-1,mid)-init) st=mid;
		else en=mid;
	}
	// cerr<<"one: "<<st<<'\n';
	if(gay && len == o){
		return answer(0, st);
	}
	ll ans1=st;
	auto bstar3=[&](ll x,ll z,ll y){
		auto isp=[&](ll x,ll y){
			return stt[x] <= stt[y] && enn[x] >= enn[y];
		};
		FOR(i,0,n-2)W[i]=0;
		FOR(i,y,n-1) if(gay || !isp(i,ans1)) { if(depth[i]==x||depth[i]==z) W[pe[i]]=1; else W[pe[i]]=0; }
		return askk(W);
	};
	st=1, en=n;
	while(en-st>1){
		ll mid=(st+en)>>1;
		if(bstar3(-1,o2,mid)-init)st=mid;
		else en=mid;
	}
	// cerr<<"two: "<<st<<'\n';
	return answer(ans1, st);
	
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...