CF2162D.Beautiful Permutation

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem.

There is a permutation∗^{\text{∗}} pp of length nn.

Someone secretly chose two integers l,rl, r (1≤l≤r≤n1 \le l \le r \le n) and modified the permutation in the following way:

  • For every index ii such that l≤i≤rl \le i \le r, set pi:=pi+1p_i := p_i + 1.

Let aa denote the resulting array obtained by modifying the permutation.

You are given an integer nn denoting the length of the permutation pp.

In one query, you are allowed to choose two integers l,rl, r (1≤l≤r≤n1 \le l \le r \le n) and ask for the sum of the subarray either of the original permutation p[l…r]p[l \dots r] or of the modified array a[l…r]a[l \dots r]. The answer to such a query will be the corresponding integer sum.

Your task is to find the pair (l,r)(l, r) that was chosen to obtain aa in no more than 40\bf{40} queries.

∗^{\text{∗}}A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in any order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (the number 22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3, but the array contains 44).

这是一个交互式问题。

存在一个长度为 nn 的排列∗^{\text{∗}} pp。

某人秘密选择了两个整数 l,rl, r(满足 1≤l≤r≤n1 \le l \le r \le n),并按如下方式修改了该排列:

  • 对每个满足 l≤i≤rl \le i \le r 的下标 ii,令 pi:=pi+1p_i := p_i + 1。

记 aa 为对排列 pp 修改后所得的数组。

你将获得一个整数 nn,表示原始排列 pp 的长度。

在一次查询中,你可以任选两个整数 l,rl, r(满足 1≤l≤r≤n1 \le l \le r \le n),并询问原始排列 p[l…r]p[l \dots r] 的子数组和,或修改后数组 a[l…r]a[l \dots r] 的子数组和。该查询的返回值即为对应的整数和。

你的任务是在不超过 40\bf{40} 次查询内,确定用于得到 aa 的那对 (l,r)(l, r)。

∗^{\text{∗}} 长度为 nn 的排列是指由 11 到 nn 这 nn 个互不相同的整数组成的任意顺序的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,但 [1,2,2][1,2,2] 不是排列(数字 22 在数组中出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中包含了 44)。

输入格式

The first line of input contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each test case contains a single integer nn (1≤n≤2⋅1041 \le n \le 2\cdot10^4) — the length of the permutation.

It is guaranteed that the sum of nn over all the test cases does not exceed 2⋅1042\cdot10^4.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例包含一个整数 nn(1≤n≤2⋅1041 \le n \le 2\cdot10^4)—— 排列的长度。

保证所有测试用例中 nn 的总和不超过 2⋅1042\cdot10^4。

输入输出样例

  • 输入#1

    2
    
    
    3
    
    4
    
    5
    
    
    4
    
    8
    
    8
    
    9

    输出#1

    1 1 2
    
    2 1 2
    
    ! 2 2
    
    1 2 4
    
    2 1 3
    
    2 3 4
    
    ! 2 4

说明/提示

For the first testcase, p=[3,1,2]p = [3, 1, 2] and l=2l = 2, r=2r = 2. Hence, the modified array aa will be equal to [3,2,2][3, 2, 2].

So, querying "1 1 2\texttt{1 1 2}" gives p1+p2=3+1=4p_1 + p_2 = 3 + 1 = 4. And querying "2 1 2\texttt{2 1 2}" gives a1+a2=3+2=5a_1 + a_2 = 3 + 2 = 5.

For the second testcase, p=[2,1,3,4]p = [2, 1, 3, 4] and l=2l = 2, r=4r = 4.

Note that the queries shown in the sample test are only for demonstration purposes, and they may not correspond to any optimal solution.

对于第一个测试用例,p=[3,1,2]p = [3, 1, 2],且 l=2l = 2,r=2r = 2。因此,修改后的数组 aa 将等于 [3,2,2][3, 2, 2]。

于是,查询 “1 1 2\texttt{1 1 2}” 的结果为 p1+p2=3+1=4p_1 + p_2 = 3 + 1 = 4;而查询 “2 1 2\texttt{2 1 2}” 的结果为 a1+a2=3+2=5a_1 + a_2 = 3 + 2 = 5。

对于第二个测试用例,p=[2,1,3,4]p = [2, 1, 3, 4],且 l=2l = 2,r=4r = 4。

注意:样例测试中展示的查询仅用于演示目的,它们未必对应任何最优解。

输入解题思路,AI测评打分。不知道怎么写?

首页