Submission #1328477

#TimeUsernameProblemLanguageResultExecution timeMemory
1328477nanaseyuzukiLibrary (JOI18_library)C++20
100 / 100
110 ms584 KiB
#include <bits/stdc++.h>
#include "library.h"
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;

#ifdef LOCAL
#include "C:\Users\Dell\Downloads\template\template\icpc-notebook\Utilities\debug.h"
#else
#define debug(...) 42
#endif

const int mn = 5e5 + 5, mod = 1e9 + 7, inf = 2e9;

int n;
vector <int> a[mn], res;

vector <int> merge(vector <int> x, vector <int> y){
	vector <int> ans(n);
	
	ans[x.front()] = 1, ans[y.front()] = 1;
	if(Query(ans) == 1){
		reverse(all(y));
		for(auto i : x) y.push_back(i);
		return y;
	}
	ans[x.front()] = 0, ans[y.front()] = 0;
	
	ans[x.front()] = 1, ans[y.back()] = 1;
	if(Query(ans) == 1){
		for(auto i : x) y.push_back(i);
		return y;
	}
	ans[x.front()] = 0, ans[y.back()] = 0;

	ans[x.back()] = 1, ans[y.front()] = 1;
	if(Query(ans) == 1){
		for(auto i : y) x.push_back(i);
		return x;
	}
	ans[x.back()] = 0, ans[y.front()] = 0;

	reverse(all(y));
	for(auto i : y) x.push_back(i);
	return x;
}

void Solve(int N) {
    n = N;
    for(int i = 0; i < n; i++) a[i].push_back(i);

    int sz = n - 1;
    for(int st = 0; st < n - 1; st ++){
    	int l = 1, r = sz, l_ = -1, r_ = -1;

    	while(l <= r){
    		int mid = (l + r) >> 1;
    		vector <int> ask(n);
    		for(int i = 0; i <= mid; i++){
    			for(auto j : a[i]) ask[j] = 1;
    		}
    		if(Query(ask) <= mid){
    			l_ = mid;
    			r = mid - 1;
    		}
    		else l = mid + 1;
    	}

    	l = 0, r = l_ - 1;
    	while(l <= r){
    		int mid = (l + r) >> 1;
    		vector <int> ask(n);
    		for(int i = mid; i <= l_; i++){
    			for(auto j : a[i]) ask[j] = 1;
    		}
    		if(Query(ask) <= l_ - mid){
    			r_ = mid;
    			l = mid + 1;
    		}
    		else r = mid - 1;
    	}
    	debug(l_, r_);

    	a[l_] = merge(a[l_], a[r_]);
    	swap(a[r_], a[sz]);
    	sz --;

    	for(int i = 0; i <= sz; i++) debug(a[i]);
    }
    for(int i = 0; i < n; i++) debug(i, a[i]);
	
	debug(a[0]);
	for(auto &i : a[0]) i ++;
    Answer(a[0]);
}
// Don't wanna lose anymore T_T
// Never let me go - Kazuo Ishiguro
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...