CF1372F.Omkar and Modes

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Ray lost his array and needs to find it by asking Omkar. Omkar is willing to disclose that the array has the following qualities:

  1. The array has nn ( 1n21051 \le n \le 2 \cdot 10^5 ) elements.
  2. Every element in the array aia_i is an integer in the range 1ai109.1 \le a_i \le 10^9.
  3. The array is sorted in nondecreasing order.

Ray is allowed to send Omkar a series of queries. A query consists of two integers, ll and rr such that 1lrn1 \le l \le r \le n . Omkar will respond with two integers, xx and ff . xx is the mode of the subarray from index ll to index rr inclusive. The mode of an array is defined by the number that appears the most frequently. If there are multiple numbers that appear the most number of times, the smallest such number is considered to be the mode. ff is the amount of times that xx appears in the queried subarray.

The array has kk ( 1kmin(25000,n)1 \le k \le \min(25000,n) ) distinct elements. However, due to Ray's sins, Omkar will not tell Ray what kk is. Ray is allowed to send at most 4k4k queries.

Help Ray find his lost array.

输入格式

The only line of the input contains a single integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ), which equals to the length of the array that you are trying to find.

输出格式

The interaction starts with reading nn .

Then you can make one type of query:

  • " ?lr? \enspace l \enspace r " ( 1lrn1 \le l \le r \le n ) where ll and rr are the bounds of the subarray that you wish to query.

The answer to each query will be in the form " xfx \enspace f " where xx is the mode of the subarray and ff is the number of times xx appears in the subarray.

  • xx satisfies ( 1x1091 \leq x \leq 10^9 ).
  • ff satisfies ( 1frl+11 \leq f \leq r-l+1 ).
  • If you make more than 4k4k queries or violate the number range in the query, you will get an output "-1."
  • If you terminate after receiving the response " 1-1 ", you will get the "Wrong answer" verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.

To output your answer, print:

  • " !a1a2an1an! \enspace a_1 \enspace a_2 \enspace \ldots \enspace a_{n-1} \enspace a_n " which is an exclamation point followed by the array with a space between every element.

And quit after that. This query is not counted towards the 4k4k queries limit.

After printing a query do not forget to output 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.

Hack Format

To hack, output 11 integer on the first line, nn ( 1n21051 \le n \le 2 \cdot 10^5 ). On the second line output nn integers a1,a2,,an1,ana_1, a_2, \ldots, a_{n-1}, a_n separated by a space such that there are at most 2500025000 distinct numbers and ajaj+1a_j \le a_{j+1} for all jj from 11 to n1n-1 .

输入输出样例

  • 输入#1

    6
    
    2 2
    
    2 2
    
    3 2
    
    2 1

    输出#1

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

说明/提示

The first query is l=1l=1 and r=6r=6 . The mode is 22 , and 22 appears 22 times, so x=2x=2 and f=2f=2 . Note that 33 also appears two times, but 22 is outputted because 22 is smaller.

The second query is l=1l=1 and r=3r=3 . The mode is 22 and 22 appears twice in the subarray with indices [1,3][1,3] .

The third query is l=4l=4 and r=6r=6 . The mode is 33 and 33 appears twice in the subarray with indices [4,6][4,6] .

The fourth query is l=3l=3 and r=4r=4 . The mode is 22 , which appears once in the subarray with indices [3,4][3,4] . Note that 33 also appears once in that range, but 22 is smaller than 33 .

首页