Submission #618858

#TimeUsernameProblemLanguageResultExecution timeMemory
618858MetalPowerXoractive (IZhO19_xoractive)C++14
100 / 100
3 ms356 KiB
#include <bits/stdc++.h>
using namespace std;

#include "interactive.h"

// ask(i) := returns value at i
// get_pairwise_xor(vec) := returns a set of pairwise xor's

map<int, int> loc;

vector<int> guess(int n){

	int lst = ask(n);

	for(int bt = 0; bt < 7; bt++){

		vector<int> vec;
		for(int i = 1; i <= n - 1; i++)
			if(i & (1 << bt)) vec.push_back(i);
		
		vector<int> st, fn;

		{
			if(vec.empty()) st = {};
			else st = get_pairwise_xor(vec);
		}

		{
			vec.push_back(n);
			fn = get_pairwise_xor(vec);
		}

		vector<int> vals;

		int a = 0, b = 0;
		for(; a < (int) st.size(); a++, b++)
			while(b < (int) fn.size() && fn[b] != st[a]) vals.push_back(fn[b++]);
		while(b < (int) fn.size()) vals.push_back(fn[b++]);

		for(int j = 1; j < (int) vals.size(); j += 2)
			loc[vals[j] ^ lst] ^= 1 << bt;
	}

	vector<int> ans;
	ans.resize(n, 0);

	for(auto x : loc) ans[x.second - 1] = x.first;
	ans[n - 1] = lst;
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...