CF1862G.The Great Equalizer
普及/提高-
通过率:0%
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 a of integers as input, after which "The Great Equalizer" will work as follows:
- Sort the current array in non-decreasing order and remove duplicate elements leaving only one occurrence of each element.
- If the current length of the array is equal to 1 , the device stops working and outputs the single number in the array — output value of the device.
- Add an arithmetic progression { n, n−1, n−2, …, 1 } to the current array, where n is the length of the current array. In other words, n−i is added to the i -th element of the array, when indexed from zero.
- Go to the first step.
To test the operation of the device, Tema came up with a certain array of integers a , and then wanted to perform q operations on the array a of the following type:
- Assign the value x ( 1≤x≤109 ) to the element ai ( 1≤i≤n ).
- Give the array a as input to the device and find out the result of the device's operation, while the array a remains unchanged during the operation of the device.
Help Tema find out the output values of the device after each operation.
输入格式
The first line of the input contains a single integer t ( 1≤t≤104 ) — the number of test cases.
Then follows the description of each test case.
The first line of each test case contains a single integer n ( 1≤n≤2⋅105 ) — the size of the array a that Tema initially came up with.
The second line of each test case contains n integers a1,a2,a3,…,an ( 1≤ai≤109 ) — the elements of the array a .
The third line of a set contains a single integer q ( 1≤q≤2⋅105 ) — the number of operations.
Each of the next q lines of a test case contains two integers i ( 1≤i≤n ) and x ( 1≤x≤109 ) - the descriptions of the operations.
It is guaranteed that the sum of the values of n and the sum of the values of q for all test cases do not exceed 2⋅105 .
输出格式
For each test case, output q integers — the output values of the device after each operation.
输入输出样例
输入#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] . 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\] . 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\] . 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] $$$$