CF1372F.Omkar and Modes

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

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 (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) elements.
  2. Every element in the array aia_i is an integer in the range 1≤ai≤109.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 1≤l≤r≤n1 \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 (1≤k≤min⁡(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.

Ray 丢失了他的数组,需要通过向 Omkar 提问来找回它。Omkar 愿意透露该数组具有以下性质:

  1. 数组包含 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)个元素。
  2. 数组中每个元素 aia_i 均为整数,且满足 1≤ai≤1091 \le a_i \le 10^9。
  3. 数组按非递减顺序排列。

Ray 可以向 Omkar 发送一系列查询。每次查询由两个整数 ll 和 rr 构成,满足 1≤l≤r≤n1 \le l \le r \le n。Omkar 将返回两个整数 xx 和 ff:

  • xx 是子数组 a[l..r]a[l..r](即从下标 ll 到 rr 的闭区间子数组)的众数(mode)。数组的众数定义为出现次数最多的数;若存在多个出现次数最多的数,则取其中最小的那个数作为众数。
  • ff 是 xx 在所查询子数组中出现的次数。

该数组共有 kk(1≤k≤min⁡(25000,n)1 \le k \le \min(25000,n))个互不相同的元素。然而,由于 Ray 的过错,Omkar 不会告诉 Ray kk 的值。Ray 最多可发送 4k4k 次查询。

请帮助 Ray 找回他丢失的数组。

输入格式

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

输入仅包含一行,其中有一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5),表示你试图构造的数组的长度。

输入输出样例

  • 输入#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.

第一个查询的 l=1l=1 且 r=6r=6。众数为 22,而 22 出现了 22 次,因此 x=2x=2 且 f=2f=2。注意,33 也出现了 22 次,但输出的是 22,因为 2<32 < 3。

第二个查询的 l=1l=1 且 r=3r=3。众数为 22,且 22 在下标范围 [1,3][1,3] 的子数组中出现了两次。

第三个查询的 l=4l=4 且 r=6r=6。众数为 33,且 33 在下标范围 [4,6][4,6] 的子数组中出现了两次。

第四个查询的 l=3l=3 且 r=4r=4。众数为 22,它在下标范围 [3,4][3,4] 的子数组中出现了一次。注意,33 在该范围内也出现了一次,但 2<32 < 3。

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

首页