CF1764G1.Doremy's Perfect DS Class (Easy Version)
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The only difference between this problem and the other two versions is the maximum number of queries. In this version, you are allowed to ask at most 30 queries. You can make hacks only if all versions of the problem are solved.
This is an interactive problem.
"Everybody! Doremy's Perfect Data Structure Class is about to start! Come and do your best if you want to have as much IQ as me!" In today's Data Structure class, Doremy is teaching everyone a powerful data structure — Doremy tree! Now she gives you a quiz to prove that you are paying attention in class.
Given an array a of length m, Doremy tree supports the query Q(l,r,k), where 1≤l≤r≤m and 1≤k≤m, which returns the number of distinct integers in the array [⌊kal⌋,⌊kal+1⌋,…,⌊kar⌋].
Doremy has a secret permutation p of integers from 1 to n. You can make queries, in one query, you give 3 integers l,r,k (1≤l≤r≤n, 1≤k≤n) and receive the value of Q(l,r,k) for the array p. Can you find the index y (1≤y≤n) such that py=1 in at most 30 queries?
Note that the permutation p is fixed before any queries are made.
Interaction
You begin the interaction by reading an integer n (3≤n≤1024) in the first line — the length of the permutation.
To make a query, you should output
- "? l r k" (1≤l≤r≤n, 1≤k≤n)
in a separate line. After each query, you should read an integer x — the value of Q(l,r,k) for p. In this version of the problem, you can make at most 30 such queries.
To give the answer, you should output
- "! y" (1≤y≤n)
in a separate line, where py=1.
After printing a query or the answer, do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.
Hacks Format
The first line of the hack contains an integer n (3≤n≤1024) — the length of the permutation.
The second line of the hack contains n distinct integers p1,p2,…,pn (1≤pi≤n) — the permutation.
本题与其他两个版本的唯一区别在于最大查询次数。在本版本中,你最多允许进行 30 次查询。仅当三个版本的问题均被解决时,才可进行 hack。
这是一个交互式问题。
“大家注意!Doremy 的完美数据结构课马上开始啦!想拥有和我一样高的智商,就来全力以赴吧!” 在今天的数据结构课上,Doremy 正在向大家讲授一种强大的数据结构——Doremy 树!现在她给出一道小测验,以检验你是否认真听讲。
给定一个长度为 m 的数组 a,Doremy 树支持查询操作 Q(l,r,k),其中 1≤l≤r≤m 且 1≤k≤m,该操作返回数组 [⌊kal⌋,⌊kal+1⌋,…,⌊kar⌋] 中不同整数的个数。
Doremy 持有一个秘密排列 p,即 1 到 n 的一个排列。你可以发起查询:每次查询提供三个整数 l,r,k(满足 1≤l≤r≤n,1≤k≤n),系统将返回该排列 p 对应的 Q(l,r,k) 值。你能否在至多 30 次查询内,找出满足 py=1 的下标 y(1≤y≤n)?
注意:排列 p 在任何查询开始前即已固定。
交互流程
交互开始时,你需首先读入第一行的一个整数 n(3≤n≤1024)——即排列的长度。
要发起一次查询,请单独输出一行:
- "? l r k"(其中 1≤l≤r≤n,1≤k≤n)
每次查询后,你需要读入一个整数 x —— 即该排列 p 对应的 Q(l,r,k) 的值。在本题版本中,你最多可进行 30 次此类查询。
要提交答案,请单独输出一行:
- "! y"(其中 1≤y≤n,且满足 py=1)
每次输出查询或答案后,务必输出换行符并刷新输出缓冲区;否则你会收到 “Idleness limit exceeded” 判定。为此,请使用以下方式:
- C++ 中:
fflush(stdout)或cout.flush(); - Java 中:
System.out.flush(); - Pascal 中:
flush(output); - Python 中:
stdout.flush(); - 其他语言请参阅相应文档。
Hack 输入格式
Hack 输入的第一行包含一个整数 n(3≤n≤1024)——即排列的长度。
第二行包含 n 个互不相同的整数 p1,p2,…,pn(1≤pi≤n)——即该排列。
输入输出样例
输入#1
5 2 2 1 3
输出#1
? 1 3 4 ? 3 5 3 ? 3 4 5 ? 3 5 2 ! 4
说明/提示
The permutation in the example is [3,5,2,1,4].
The input and output for example illustrate possible interaction on that test (empty lines are inserted only for clarity).
In this interaction process:
- For the first query, ⌊43⌋=0,⌊45⌋=1,⌊42⌋=0, so the answer is 2.
- For the second query, ⌊32⌋=0,⌊31⌋=0,⌊34⌋=1, so the answer is still 2.
- For the third query, ⌊52⌋=0,⌊51⌋=0, so the answer is 1.
- For the fourth query, ⌊22⌋=1,⌊21⌋=0,⌊24⌋=2, so the answer is 3.
The correct answer is got after 4 queries, so this process will be judged correct.
示例中的排列为 [3,5,2,1,4]。
示例的输入与输出展示了在该测试用例上可能发生的交互过程(空行仅用于增强可读性)。
在此交互过程中:
- 对于第一个查询,⌊43⌋=0,⌊45⌋=1,⌊42⌋=0,因此答案为 2。
- 对于第二个查询,⌊32⌋=0,⌊31⌋=0,⌊34⌋=1,因此答案仍为 2。
- 对于第三个查询,⌊52⌋=0,⌊51⌋=0,因此答案为 1。
- 对于第四个查询,⌊22⌋=1,⌊21⌋=0,⌊24⌋=2,因此答案为 3。
在 4 次查询后得到了正确答案,因此该过程将被判定为正确。
输入解题思路,AI测评打分。不知道怎么写?