CF1862G.The Great Equalizer

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Tema bought an old device with a small screen and a worn-out inscription "The Great Equalizer" on the side.

The seller said that the device needs to be given an array aa of integers as input, after which "The Great Equalizer" will work as follows:

  1. Sort the current array in non-decreasing order and remove duplicate elements leaving only one occurrence of each element.
  2. If the current length of the array is equal to 11, the device stops working and outputs the single number in the array — output value of the device.
  3. Add an arithmetic progression {n, n−1, n−2, …, 1n,\ n - 1,\ n - 2,\ \ldots,\ 1} to the current array, where nn is the length of the current array. In other words, n−in - i is added to the ii-th element of the array, when indexed from zero.
  4. Go to the first step.

To test the operation of the device, Tema came up with a certain array of integers aa, and then wanted to perform qq operations on the array aa of the following type:

  1. Assign the value xx (1≤x≤1091 \le x \le 10^9) to the element aia_i (1≤i≤n1 \le i \le n).
  2. Give the array aa as input to the device and find out the result of the device's operation, while the array aa remains unchanged during the operation of the device.

Help Tema find out the output values of the device after each operation.

特玛买了一台旧设备,屏幕很小,侧面有一行磨损的铭文:“伟大的均衡器”。

卖家称,该设备需要输入一个整数数组 aa,之后“伟大的均衡器”将按如下方式工作:

  1. 将当前数组按非递减顺序排序,并去除重复元素,使每个元素仅保留一次。
  2. 若当前数组长度为 11,则设备停止工作,并输出数组中唯一的那个数——即设备的输出值。
  3. 向当前数组添加一个等差数列 {n, n−1, n−2, …, 1}\{n,\ n - 1,\ n - 2,\ \ldots,\ 1\},其中 nn 是当前数组的长度。换言之,对从零开始索引的第 ii 个元素,加上 n−in - i。
  4. 返回第一步。

为测试设备运行情况,特玛构思了一个整数数组 aa,并希望对数组 aa 执行 qq 次如下类型的操作:

  1. 将位置 aia_i(1≤i≤n1 \le i \le n)的元素赋值为 xx(1≤x≤1091 \le x \le 10^9)。
  2. 将数组 aa 作为输入提供给设备,并求出设备运行后得到的结果;注意:在设备运行过程中,数组 aa 本身保持不变。

请帮助特玛求出每次操作后设备的输出值。

输入格式

The first line of the input contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Then follows the description of each test case.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the size of the array aa that Tema initially came up with.

The second line of each test case contains nn integers a1,a2,a3,…,ana_1, a_2, a_3, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the elements of the array aa.

The third line of a set contains a single integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of operations.

Each of the next qq lines of a test case contains two integers ii (1≤i≤n1 \le i \le n) and xx (1≤x≤1091 \le x \le 10^9) - the descriptions of the operations.

It is guaranteed that the sum of the values of nn and the sum of the values of qq for all test cases do not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

随后是每个测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示 Tema 最初构造的数组 aa 的大小。

每个测试用例的第二行包含 nn 个整数 a1,a2,a3,…,ana_1, a_2, a_3, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 表示数组 aa 的元素。

每个测试用例的第三行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5)—— 表示操作的数量。

接下来的 qq 行,每行包含两个整数 ii(1≤i≤n1 \le i \le n)和 xx(1≤x≤1091 \le x \le 10^9)—— 表示一次操作的描述。

保证所有测试用例中 nn 的总和与 qq 的总和均不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output qq integers — the output values of the device after each operation.

对于每个测试用例,输出 qq 个整数——即设备在每次操作后的输出值。

输入输出样例

  • 输入#1

    4
    3
    2 4 8
    3
    1 6
    2 10
    3 1
    5
    1 2 2 2 2
    1
    5 3
    2
    5 6
    7
    1 2
    1 7
    1 7
    2 5
    1 2
    2 7
    2 2
    5
    2 5 1 10 6
    10
    1 7
    4 8
    2 5
    1 4
    2 8
    3 4
    1 9
    3 7
    3 4
    3 1

    输出#1

    10 12 15 
    4 
    10 8 8 9 8 12 2 
    14 12 12 11 11 10 11 10 11 14

说明/提示

Let's consider the first example of the input.

Initially, the array of numbers given as input to the device will be [6,4,8][6, 4, 8]. It will change as follows: $$[6, 4, 8] \rightarrow [4, 6, 8] \rightarrow [7, 8, 9] \rightarrow [10, 10, 10] \rightarrow [10]$$

Then, the array of numbers given as input to the device will be [6,10,8][6, 10, 8]. It will change as follows: $$[6, 10, 8] \rightarrow [6, 8, 10] \rightarrow [9, 10, 11] \rightarrow [12, 12, 12] \rightarrow [12]$$

The last array of numbers given as input to the device will be [6,10,1][6, 10, 1]. It will change as follows: $$[6, 10, 1] \rightarrow [1, 6, 10] \rightarrow [4, 8, 11] \rightarrow [7, 10, 12] \rightarrow [10, 12, 13] \rightarrow [13, 14, 14] \rightarrow [13, 14] \rightarrow [15, 15] \rightarrow [15]$$

我们考虑输入的第一个例子。

最初,输入到该设备的数字数组为 [6,4,8][6, 4, 8]。它将按如下方式变化: $$[6, 4, 8] \rightarrow [4, 6, 8] \rightarrow [7, 8, 9] \rightarrow [10, 10, 10] \rightarrow [10]$$

接着,输入到该设备的数字数组为 [6,10,8][6, 10, 8]。它将按如下方式变化: $$[6, 10, 8] \rightarrow [6, 8, 10] \rightarrow [9, 10, 11] \rightarrow [12, 12, 12] \rightarrow [12]$$

最后,输入到该设备的数字数组为 [6,10,1][6, 10, 1]。它将按如下方式变化: $$[6, 10, 1] \rightarrow [1, 6, 10] \rightarrow [4, 8, 11] \rightarrow [7, 10, 12] \rightarrow [10, 12, 13] \rightarrow [13, 14, 14] \rightarrow [13, 14] \rightarrow [15, 15] \rightarrow [15]$$

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

首页