#P12090. Interactive Hidden Permutation
Interactive Hidden Permutation
Interactive Hidden Permutation
This is an interactive problem. The interaction library is non-adaptive.
There is a hidden permutation \(p_1, p_2, \ldots, p_n\) of \(\{1,2,\ldots,n\}\). You can make queries of the following form:
Query: Given a permutation \(v_1,v_2,\ldots,v_n\) of \(\{1,2,\ldots,n\}\), the interactor returns
\[ \sum_{i=1}^{n-1} \left| p_{v_i} - p_{v_{i+1}} \right| \]
Your task is to find any permutation \(p'\) that is equivalent to \(p\).
Two permutations \(p\) and \(p'\) are defined to be equivalent if for every permutation \(v\) the answer to the query is the same for both, that is:
\[ \sum_{i=1}^{n-1} \left| p_{v_i} - p_{v_{i+1}} \right| = \sum_{i=1}^{n-1} \left| p'_{v_i} - p'_{v_{i+1}} \right| \]Implementation Details:
You should not implement the main function.
You must add the following declarations at the top of your file:
int query(vector); void answer(vector);
You should implement the following function:
void solve(int n);
In each test case, the function solve
is called exactly once to determine a permutation of \(\{1,2,\ldots,n\}\) that is equivalent to the hidden permutation.
You can call the following functions:
int query(vector<int> v);
— Sends a query. The vectorv
(0-indexed) is a permutation representing \(v_1,v_2,\ldots,v_n\) and the function returns \( \sum_{i=1}^{n-1} |p_{v_i} - p_{v_{i+1}}| \).void answer(vector<int> p);
— Reports your answer permutation. After callinganswer
, the program should terminate immediately.
Note: In actual interactive settings you do not have direct access to the hidden permutation. For local simulation and testing, the hidden permutation will be provided via input.
inputFormat
No conventional input. For local testing, the first line contains the integer \(n\) and the second line contains \(n\) space-separated integers representing the hidden permutation.
outputFormat
Your program should call answer
with a permutation equivalent to the hidden permutation.
sample
3
1 2 3
1 2 3