#P17272. [eJOI 2026] XORting

    ID: 17391 Type: RemoteJudge 2000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>贪心交互题Special JudgeeJOI(欧洲)位运算2026

[eJOI 2026] XORting

题目描述

This is an interactive problem.

Iliyan has played a prank on Jonas: he has hidden a permutation p0,p1,…,pN−1p_0,p_1,\ldots,p_{N-1} of the integers from 00 to N−1N-1. Jonas is desperate to recover it, and you have agreed to help him.

Iliyan will not reveal the permutation outright, but he will answer questions of the following kind: choose two indices ii and jj with 0≤i,j<N0\le i,j<N, and he tells you the bitwise XOR of pip_i and pjp_j.

The bitwise XOR of two numbers, denoted by ⊕\oplus, performs logical exclusive OR on every pair of corresponding bits. A result bit is 11 if exactly one input bit is 11, and 00 otherwise. For example, 75⊕29=8675\oplus 29=86 because 1001011(2)⊕0011101(2)=1010110(2)1001011_{(2)}\oplus 0011101_{(2)}=1010110_{(2)}. In C++, the XOR of a and b is written a ^ b.

Iliyan is willing to answer at most QQ questions.

These questions cannot always determine the hidden permutation uniquely. A permutation a0,a1,…,aN−1a_0,a_1,\ldots,a_{N-1} is indistinguishable from pp if ai⊕aj=pi⊕pja_i\oplus a_j=p_i\oplus p_j for every pair 0≤i,j<N0\le i,j<N. Every answer is identical whether the hidden permutation is pp or aa, so no sequence of questions can distinguish them. The permutation pp is always indistinguishable from itself, and there may be no other such permutation.

Your task is to find the lexicographically smallest permutation indistinguishable from pp.

A permutation x0,x1,…,xN−1x_0,x_1,\ldots,x_{N-1} is lexicographically smaller than y0,y1,…,yN−1y_0,y_1,\ldots,y_{N-1} if, at the first position kk where they differ, xk<ykx_k<y_k. For example, [2,0,1,4,3][2,0,1,4,3] is lexicographically smaller than [2,0,3,1,4][2,0,3,1,4] because their first difference is at k=2k=2 and 1<31<3.

The hidden permutation is fixed before your program starts and does not change in response to your questions.

Implementation details

Implement the following function:

std::vector<int> solve(int N)
  • NN: the number of elements in the permutation.

This function is called exactly TT times, once for each hidden permutation. It must return the lexicographically smallest permutation indistinguishable from the permutation hidden for that call.

To communicate with the jury, you may call:

int get_xor(int i, int j)

Each call returns pi⊕pjp_i\oplus p_j. Both arguments must be valid indices. Otherwise, your solution receives Output isn't correct: Invalid argument. The function responds in constant time O(1)O(1).

The value of QQ is fixed for each subtask and is not passed to your program.

输入格式

Input format:

  • line 11: two integers TT and QtypeQ_{\mathrm{type}}, where QtypeQ_{\mathrm{type}} is either 11 or 22;
  • the following 2T2T lines describe the tests:
    • line 2i2i: one integer NiN_i;
    • line 2i+12i+1: NiN_i integers p0,p1,…,pNi−1p_0,p_1,\ldots,p_{N_i-1}.

If Qtype=1Q_{\mathrm{type}}=1, then Qi=NiQ_i=N_i; if Qtype=2Q_{\mathrm{type}}=2, then Qi=Ni2Q_i=N_i^2.

输出格式

Output format:

  • line ii: the permutation returned by your program on the ii-th test.

提示

Example

Consider the following interaction, in which solve is called twice:

Participant program Jury program
solve(4)
get_xor(0, 1) returns 2
get_xor(0, 2) returns 3
get_xor(0, 3) returns 1
get_xor(1, 2)
get_xor(1, 3) returns 3
get_xor(2, 3) returns 2
return {0, 2, 3, 1}
solve(1)
return {0}

Explanation of the first call

The hidden permutation is [2,0,1,3][2,0,1,3], but the lexicographically smallest indistinguishable permutation is [0,2,3,1][0,2,3,1]. Six questions were asked for N1=4N_1=4, which is allowed because Q1=N12=16Q_1=N_1^2=16 in this subtask.

Explanation of the second call

The only possible permutation for N2=1N_2=1 is [0][0].

Constraints

  • 1≤Ni≤2201\le N_i\le 2^{20} for every 1≤i≤T1\le i\le T, where NiN_i is the value of NN in the ii-th call to solve
  • 1≤T≤2101\le T\le 2^{10}
  • T⋅max⁡(N1,N2,…,NT)≤225T\cdot\max(N_1,N_2,\ldots,N_T)\le 2^{25}
  • During the ii-th call to solve, you may ask at most QiQ_i questions, where QiQ_i is either NiN_i or Ni2N_i^2, depending on the subtask

Subtasks

Subtask Points NiN_i TT QiQ_i Additional constraints
0 - Ni2N_i^2 The example.
1 7 ≤23\le 2^3 2102^{10} -
2 18 ≤27\le 2^7 252^5
3 5 ≤211\le 2^{11}
4 NiN_i
5 ≤218\le 2^{18} Ni=2kN_i=2^k for some integer kk.
6 NiN_i is odd.
7 30 -
8 25 ≤220\le 2^{20}