CF2163D1.Diadrash (Easy Version)

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the Easy version of the problem. The difference between the versions is that in this version, you can make at most max⁡(300,⌈n2⌉+2)\max(300, \lceil\frac{n}{2}\rceil+2) queries. You can hack only if you solved all versions of this problem.

This problem is interactive.

There is a permutation∗^{\text{∗}} pp of the integers from 00 to n−1n-1 hidden from you. Additionally, you are given qq ranges [l1,r1],[l2,r2],…,[lq,rq][l_1, r_1], [l_2, r_2], \ldots, [l_q, r_q] where 1≤li≤ri≤n1 \le l_i \le r_i \le n.

You need to discover the maximum MEX⁡\operatorname{MEX} among the values of pp in the qq ranges that are given to you in the input. Formally, you must discover the value of max⁡i=1qMEX⁡([pli,pli+1,…,pri])\max _{i=1}^q {\operatorname{MEX}([p_{l_i}, p_{l_i+1}, \ldots, p_{r_i}])}†^{\text{†}}. To do this, you may make at most max⁡(300,⌈n2⌉+2)\max(300, \lceil\frac{n}{2}\rceil+2) queries of the following form:

  • Choose any two integers 1≤l≤r≤n1 \le l \le r \le n and you will receive the value MEX⁡([pl,pl+1,…,pr])\operatorname{MEX}([p_{l}, p_{l+1}, \ldots, p_{r}]).

∗^{\text{∗}}A permutation of the integers from 00 to n−1n-1 is a sequence of nn elements where every integer from 00 to n−1n-1 appears exactly once. For example, the sequence [0,3,1,2][0, 3, 1, 2] is a permutation, but the sequence [0,0,2,1][0, 0, 2, 1] is not.

†^{\text{†}}The MEX⁡\operatorname{MEX} of a sequence is defined as the smallest non-negative integer that does not appear in that sequence. For example, MEX⁡([0,0,1,3])=2\operatorname{MEX}([0, 0, 1, 3]) = 2 and MEX⁡([1,2,2])=0.\operatorname{MEX}([1, 2, 2]) = 0.

这是本题的简单版本。两个版本的区别在于:在本版本中,你最多可以进行 max⁡(300,⌈n2⌉+2)\max(300, \lceil\frac{n}{2}\rceil+2) 次查询。仅当你解决了本题的所有版本时,才可进行 Hack。

本题为交互式问题。

存在一个你无法看到的、由 00 到 n−1n-1 的整数构成的排列∗^{\text{∗}} pp。此外,你还给定 qq 个区间 [l1,r1],[l2,r2],…,[lq,rq][l_1, r_1], [l_2, r_2], \ldots, [l_q, r_q],其中 1≤li≤ri≤n1 \le l_i \le r_i \le n。

你需要确定给定的 qq 个区间中,pp 在各区间上取值所构成子序列的最大 MEX⁡\operatorname{MEX}。形式化地,你需要求出 max⁡i=1qMEX⁡([pli,pli+1,…,pri])\max _{i=1}^q {\operatorname{MEX}([p_{l_i}, p_{l_i+1}, \ldots, p_{r_i}])}†^{\text{†}} 的值。为此,你最多可进行 max⁡(300,⌈n2⌉+2)\max(300, \lceil\frac{n}{2}\rceil+2) 次如下形式的查询:

  • 任选两个整数 1≤l≤r≤n1 \le l \le r \le n,你将收到 MEX⁡([pl,pl+1,…,pr])\operatorname{MEX}([p_{l}, p_{l+1}, \ldots, p_{r}]) 的值。

∗^{\text{∗}}由 00 到 n−1n-1 的整数组成的排列是一个长度为 nn 的序列,其中每个整数 00 至 n−1n-1 恰好出现一次。例如,序列 [0,3,1,2][0, 3, 1, 2] 是一个排列,但序列 [0,0,2,1][0, 0, 2, 1] 不是。

†^{\text{†}}一个序列的 MEX⁡\operatorname{MEX} 定义为该序列中未出现的最小非负整数。例如,MEX⁡([0,0,1,3])=2\operatorname{MEX}([0, 0, 1, 3]) = 2,而 MEX⁡([1,2,2])=0\operatorname{MEX}([1, 2, 2]) = 0。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The first line of each test case contains exactly two integers nn and qq (4≤n≤1044 \le n \le 10^4, 1≤q≤3⋅1051 \le q \le 3 \cdot 10^5) — the size of the permutation and the number of ranges, respectively.

The ii-th of the next qq lines contains two integers li,ril_i, r_i (1≤li≤ri≤n1 \le l_i \le r_i \le n).

It is guaranteed that the sum of nn and qq do not exceed 10410^4 and 3⋅1053 \cdot 10^5 respectively over all test cases.

Additional Constraint: it is guaranteed that no range is repeated in the same test case.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是各测试用例的描述。

每个测试用例的第一行恰好包含两个整数 nn 和 qq(4≤n≤1044 \le n \le 10^4,1≤q≤3⋅1051 \le q \le 3 \cdot 10^5)——分别表示排列的长度和查询区间的数量。

接下来的 qq 行中,第 ii 行包含两个整数 li,ril_i, r_i(1≤li≤ri≤n1 \le l_i \le r_i \le n)。

保证所有测试用例中 nn 的总和不超过 10410^4,且 qq 的总和不超过 3⋅1053 \cdot 10^5。

附加约束:保证在同一测试用例中不会出现重复的区间。

输入输出样例

  • 输入#1

    3
    4 3
    1 2
    2 4
    1 3
    
    2
    
    0
    
    1
    
    4
    
    6 6
    1 2
    2 4
    3 3
    4 6
    5 5
    6 6
    
    6
    
    1
    
    2
    
    4 4
    1 1
    2 2
    3 3
    4 4

    输出#1

    ? 1 3
    
    ? 4 4
    
    ? 1 1
    
    ? 1 4
    
    ! 2
    
    
    
    
    
    
    
    ? 1 6
    
    ? 3 3
    
    ? 2 4
    
    ! 2
    
    
    
    
    
    ! 1

说明/提示

In the first example, the hidden permutation is p=[0,3,1,2]p = [0, 3, 1, 2] and the ranges are [1,2],[2,4],[1,3][1, 2], [2, 4], [1, 3]. The third range is optimal, as MEX⁡([p1,p2,p3])=MEX⁡([0,3,1])=2\operatorname{MEX}([p_1, p_2, p_3]) = \operatorname{MEX}([0, 3, 1]) = 2, which is maximum.

In our first query, we ask about l=1,r=3l = 1, r = 3 and the judge gives us the value MEX⁡([p1,p2,p3])=2\operatorname{MEX}([p_1, p_2, p_3]) = 2. In the second query, we ask about l=4,r=4l = 4, r = 4 and the judge gives us the value MEX⁡([p4])=0\operatorname{MEX}([p_4]) = 0. Likewise, MEX⁡([p1])=1\operatorname{MEX}([p_1]) = 1 and MEX⁡([p1,p2,p3,p4])=4\operatorname{MEX}([p_1, p_2, p_3, p_4]) = 4.

Somehow, we figure out that the answer we are looking for is 22.

In the second example, p=[3,5,0,1,4,2]p = [3, 5, 0, 1, 4, 2].

In the third example, p=[0,1,2,3]p = [0, 1, 2, 3].

Note that this is just an explanation of the way the interaction works and does not show any strategy to solve the problem.

在第一个例子中,隐藏的排列为 p=[0,3,1,2]p = [0, 3, 1, 2],查询区间为 [1,2],[2,4],[1,3][1, 2], [2, 4], [1, 3]。第三个区间是最优的,因为 MEX⁡([p1,p2,p3])=MEX⁡([0,3,1])=2\operatorname{MEX}([p_1, p_2, p_3]) = \operatorname{MEX}([0, 3, 1]) = 2,该值达到最大。

在我们的第一次查询中,我们询问区间 l=1,r=3l = 1, r = 3,评测机返回值 MEX⁡([p1,p2,p3])=2\operatorname{MEX}([p_1, p_2, p_3]) = 2。在第二次查询中,我们询问区间 l=4,r=4l = 4, r = 4,评测机返回值 MEX⁡([p4])=0\operatorname{MEX}([p_4]) = 0。同理,MEX⁡([p1])=1\operatorname{MEX}([p_1]) = 1,且 MEX⁡([p1,p2,p3,p4])=4\operatorname{MEX}([p_1, p_2, p_3, p_4]) = 4。

最终,我们设法推断出所求答案为 22。

在第二个例子中,p=[3,5,0,1,4,2]p = [3, 5, 0, 1, 4, 2]。

在第三个例子中,p=[0,1,2,3]p = [0, 1, 2, 3]。

注意:以上仅是对交互机制的说明,并未展示任何解决该问题的策略。

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

首页