Monotone Subsequence
시간 제한2초메모리 제한2048 MB
길이 n^2+1인 숨겨진 순열에서 증가하거나 감소하는 길이 n+1 부분수열을 찾는다. 선택한 인덱스 집합의 왼쪽부터 보이는 최댓값들을 돌려주는 질의를 최대 n번 쓸 수 있다.
문제
This is an interactive problem.
Faker is being naughty again. You asked him to create a nice query problem, but he created an interactive problem where he is answering a query instead! Faker hid a permutation from you, and you have to infer some interesting information by interacting with him.
You are given an integer . Faker hid a hidden permutation* of length . Your goal is to find a monotone subsequence (either increasing or decreasing) of the hidden permutation, with length exactly . It can be proved that every permutation of length contains a monotone subsequence of length . For more information about the proof, you can check out this Wikipedia page.
To find it, you can make at most skyscraper queries to the interactor, which is defined as follows:
- You provide a set of indices as a strictly increasing sequence: .
- The interactor considers the values of the hidden permutation at these indices: .
- The interactor then returns the indices corresponding to the visible skyscrapers from this set. An index is visible if its value is greater than the values of all preceding elements in your query, i.e., for all . This is equivalent to finding the indices of the left-to-right maxima of the sequence .
After making at most queries, you must report a valid monotone subsequence of length exactly .
Note that the permutation is fixed before any queries are made and does not depend on the queries.
*A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).
입력
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first and only line of each test case contains a single integer ().
It is guaranteed that the sum of over all test cases does not exceed .
힌트
For the first test case, . The hidden permutation is .
- For the query
? 2 1 2, the visible skyscrapers are at indices and . The interactor returns2 1 2. - An increasing subsequence of length at indices is reported.
For the second test case, . The hidden permutation is .
- For the query
? 3 1 2 3, the visible skyscraper is at index . The interactor returns1 1. - For the query
? 3 2 3 5, the visible skyscrapers are at indices and . The interactor returns2 2 3. - A decreasing subsequence of length at indices is reported.
Although Faker will play the role of interactor, the interactor will never lie to you.