A16091 | The Great Equalizer
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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:
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 $1$ , 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,\ \ldots,\ 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.
4. 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:
1. Assign the value $x$ ( $1 \le x \le 10^9$ ) to the element $a_i$ ( $1 \le i \le n$ ).
2. 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 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:
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 $1$ , 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,\ \ldots,\ 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.
4. 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:
1. Assign the value $x$ ( $1 \le x \le 10^9$ ) to the element $a_i$ ( $1 \le i \le n$ ).
2. 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 \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 $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the size of the array $a$ that Tema initially came up with.
The second line of each test case contains $n$ integers $a_1, a_2, a_3, \ldots, a_n$ ( $1 \le a_i \le 10^9$ ) — the elements of the array $a$ .
The third line of a set contains a single integer $q$ ( $1 \le q \le 2 \cdot 10^5$ ) — the number of operations.
Each of the next $q$ lines of a test case contains two integers $i$ ( $1 \le i \le n$ ) and $x$ ( $1 \le x \le 10^9$ ) - 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 \cdot 10^5$ .
Then follows the description of each test case.
The first line of each test case contains a single integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the size of the array $a$ that Tema initially came up with.
The second line of each test case contains $n$ integers $a_1, a_2, a_3, \ldots, a_n$ ( $1 \le a_i \le 10^9$ ) — the elements of the array $a$ .
The third line of a set contains a single integer $q$ ( $1 \le q \le 2 \cdot 10^5$ ) — the number of operations.
Each of the next $q$ lines of a test case contains two integers $i$ ( $1 \le i \le n$ ) and $x$ ( $1 \le x \le 10^9$ ) - 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 \cdot 10^5$ .
输出格式
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] $$ </p><p>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] $$ </p><p>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] $$$$
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] $$ </p><p>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] $$ </p><p>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] $$$$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted