CF1764G1.Doremy's Perfect DS Class (Easy Version)

普及/提高-

通过率:0%

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\mathbf{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 aa of length mm , Doremy tree supports the query Q(l,r,k)Q(l,r,k) , where 1lrm1 \leq l \leq r \leq m and 1km1 \leq k \leq m , which returns the number of distinct integers in the array [alk,al+1k,,ark]\left[\lfloor\frac{a_l}{k} \rfloor, \lfloor\frac{a_{l+1}}{k} \rfloor, \ldots, \lfloor\frac{a_r}{k} \rfloor\right] .

Doremy has a secret permutation pp of integers from 11 to nn . You can make queries, in one query, you give 33 integers l,r,kl,r,k ( 1lrn1 \leq l \leq r \leq n , 1kn1 \leq k \leq n ) and receive the value of Q(l,r,k)Q(l,r,k) for the array pp . Can you find the index yy ( 1yn1 \leq y \leq n ) such that py=1p_y=1 in at most 30\mathbf{30} queries?

Note that the permutation pp is fixed before any queries are made.

输入格式

输出格式

You begin the interaction by reading an integer nn ( 3n10243 \le n \le 1024 ) in the first line — the length of the permutation.

To make a query, you should output

  • "? l r kl\ r\ k " ( 1lrn1 \leq l \leq r \leq n , 1kn1 \leq k \leq n )

in a separate line. After each query, you should read an integer xx — the value of Q(l,r,k)Q(l,r,k) for pp . In this version of the problem, you can make at most 3030 such queries.To give the answer, you should output

  • "! yy " ( 1yn1 \leq y \leq n )

in a separate line, where py=1p_y=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 nn ( 3n10243 \le n \le 1024 ) — the length of the permutation.

The second line of the hack contains nn distinct integers p1,p2,,pnp_1,p_2,\ldots,p_n ( 1pin1 \le p_i\le n ) — the permutation.

输入输出样例

  • 输入#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][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, 34=0,54=1,24=0\lfloor\frac{3}{4}\rfloor=0,\lfloor\frac{5}{4}\rfloor=1,\lfloor\frac{2}{4}\rfloor=0 , so the answer is 22 .
  • For the second query, 23=0,13=0,43=1\lfloor\frac{2}{3}\rfloor=0,\lfloor\frac{1}{3}\rfloor=0,\lfloor\frac{4}{3}\rfloor=1 , so the answer is still 22 .
  • For the third query, 25=0,15=0\lfloor\frac{2}{5}\rfloor=0,\lfloor\frac{1}{5}\rfloor=0 , so the answer is 11 .
  • For the fourth query, 22=1,12=0,42=2\lfloor\frac{2}{2}\rfloor=1,\lfloor\frac{1}{2}\rfloor=0,\lfloor\frac{4}{2}\rfloor=2 , so the answer is 33 .

The correct answer is got after 44 queries, so this process will be judged correct.

首页