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,⌈2n⌉+2) queries. You can hack only if you solved all versions of this problem.
This problem is interactive.
There is a permutation∗ p of the integers from 0 to n−1 hidden from you. Additionally, you are given q ranges [l1,r1],[l2,r2],…,[lq,rq] where 1≤li≤ri≤n.
You need to discover the maximum MEX among the values of p in the q ranges that are given to you in the input. Formally, you must discover the value of maxi=1qMEX([pli,pli+1,…,pri])†. To do this, you may make at most max(300,⌈2n⌉+2) queries of the following form:
- Choose any two integers 1≤l≤r≤n and you will receive the value MEX([pl,pl+1,…,pr]).
∗A permutation of the integers from 0 to n−1 is a sequence of n elements where every integer from 0 to n−1 appears exactly once. For example, the sequence [0,3,1,2] is a permutation, but the sequence [0,0,2,1] is not.
†The 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 and MEX([1,2,2])=0.
这是本题的简单版本。两个版本的区别在于:在本版本中,你最多可以进行 max(300,⌈2n⌉+2) 次查询。仅当你解决了本题的所有版本时,才可进行 Hack。
本题为交互式问题。
存在一个你无法看到的、由 0 到 n−1 的整数构成的排列∗ p。此外,你还给定 q 个区间 [l1,r1],[l2,r2],…,[lq,rq],其中 1≤li≤ri≤n。
你需要确定给定的 q 个区间中,p 在各区间上取值所构成子序列的最大 MEX。形式化地,你需要求出 maxi=1qMEX([pli,pli+1,…,pri])† 的值。为此,你最多可进行 max(300,⌈2n⌉+2) 次如下形式的查询:
- 任选两个整数 1≤l≤r≤n,你将收到 MEX([pl,pl+1,…,pr]) 的值。
∗由 0 到 n−1 的整数组成的排列是一个长度为 n 的序列,其中每个整数 0 至 n−1 恰好出现一次。例如,序列 [0,3,1,2] 是一个排列,但序列 [0,0,2,1] 不是。
†一个序列的 MEX 定义为该序列中未出现的最小非负整数。例如,MEX([0,0,1,3])=2,而 MEX([1,2,2])=0。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). The description of the test cases follows.
The first line of each test case contains exactly two integers n and q (4≤n≤104, 1≤q≤3⋅105) — the size of the permutation and the number of ranges, respectively.
The i-th of the next q lines contains two integers li,ri (1≤li≤ri≤n).
It is guaranteed that the sum of n and q do not exceed 104 and 3⋅105 respectively over all test cases.
Additional Constraint: it is guaranteed that no range is repeated in the same test case.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤100)。随后是各测试用例的描述。
每个测试用例的第一行恰好包含两个整数 n 和 q(4≤n≤104,1≤q≤3⋅105)——分别表示排列的长度和查询区间的数量。
接下来的 q 行中,第 i 行包含两个整数 li,ri(1≤li≤ri≤n)。
保证所有测试用例中 n 的总和不超过 104,且 q 的总和不超过 3⋅105。
附加约束:保证在同一测试用例中不会出现重复的区间。
输入输出样例
输入#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] and the ranges are [1,2],[2,4],[1,3]. The third range is optimal, as MEX([p1,p2,p3])=MEX([0,3,1])=2, which is maximum.
In our first query, we ask about l=1,r=3 and the judge gives us the value MEX([p1,p2,p3])=2. In the second query, we ask about l=4,r=4 and the judge gives us the value MEX([p4])=0. Likewise, MEX([p1])=1 and MEX([p1,p2,p3,p4])=4.
Somehow, we figure out that the answer we are looking for is 2.
In the second example, p=[3,5,0,1,4,2].
In the third example, 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],查询区间为 [1,2],[2,4],[1,3]。第三个区间是最优的,因为 MEX([p1,p2,p3])=MEX([0,3,1])=2,该值达到最大。
在我们的第一次查询中,我们询问区间 l=1,r=3,评测机返回值 MEX([p1,p2,p3])=2。在第二次查询中,我们询问区间 l=4,r=4,评测机返回值 MEX([p4])=0。同理,MEX([p1])=1,且 MEX([p1,p2,p3,p4])=4。
最终,我们设法推断出所求答案为 2。
在第二个例子中,p=[3,5,0,1,4,2]。
在第三个例子中,p=[0,1,2,3]。
注意:以上仅是对交互机制的说明,并未展示任何解决该问题的策略。
输入解题思路,AI测评打分。不知道怎么写?