A14049 | Last minute enhancements
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Athenaeus has just finished creating his latest musical composition and will present it tomorrow to the people of Athens. Unfortunately, the melody is rather dull and highly likely won't be met with a warm reception.
His song consists of $n$ notes, which we will treat as positive integers. The diversity of a song is the number of different notes it contains. As a patron of music, Euterpe watches over composers and guides them throughout the process of creating new melodies. She decided to help Athenaeus by changing his song to make it more diverse.
Being a minor goddess, she cannot arbitrarily change the song. Instead, for each of the $n$ notes in the song, she can either leave it as it is or increase it by $1$ .
Given the song as a sequence of integers describing the notes, find out the maximal, achievable diversity.
His song consists of $n$ notes, which we will treat as positive integers. The diversity of a song is the number of different notes it contains. As a patron of music, Euterpe watches over composers and guides them throughout the process of creating new melodies. She decided to help Athenaeus by changing his song to make it more diverse.
Being a minor goddess, she cannot arbitrarily change the song. Instead, for each of the $n$ notes in the song, she can either leave it as it is or increase it by $1$ .
Given the song as a sequence of integers describing the notes, find out the maximal, achievable diversity.
输入格式
The input consists of multiple test cases. The first line contains an integer $t$ ( $1 \leq t \leq 10\,000$ ) — the number of test cases. Then $t$ test cases follow, each one is described in two lines.
In the first line of each test case there is a single integer $n$ ( $1 \leq n \leq 10^5$ ) denoting the length of the song. The next line contains a sequence of $n$ integers $x_1, x_2, \ldots, x_n$ $(1 \leq x_1 \leq x_2 \leq \ldots \leq x_n \leq 2 \cdot n)$ , describing the song.
The sum of $n$ over all test cases does not exceed $10^5$ .
In the first line of each test case there is a single integer $n$ ( $1 \leq n \leq 10^5$ ) denoting the length of the song. The next line contains a sequence of $n$ integers $x_1, x_2, \ldots, x_n$ $(1 \leq x_1 \leq x_2 \leq \ldots \leq x_n \leq 2 \cdot n)$ , describing the song.
The sum of $n$ over all test cases does not exceed $10^5$ .
输出格式
For each test case, you should output a single line containing precisely one integer, the maximal diversity of the song, i.e. the maximal possible number of different elements in the final sequence.
输入输出样例
输入 #1
5 6 1 2 2 2 5 6 2 4 4 6 1 1 3 4 4 5 1 1 6 1 1 1 2 2 2
输出 #1
5 2 6 1 3
In the first test case, Euterpe can increase the second, fifth and sixth element to obtain the sequence $1, \underline{3}, 2, 2, \underline{6}, \underline{7}$ , which has $5$ different elements (increased elements are underlined).
In the second test case, Euterpe can increase the first element to obtain the sequence $\underline{5}, 4$ , which has $2$ different elements.
In the third test case, Euterpe can increase the second, fifth and sixth element to obtain the sequence $1, \underline{2}, 3, 4, \underline{5}, \underline{6}$ , which has $6$ different elements.
In the second test case, Euterpe can increase the first element to obtain the sequence $\underline{5}, 4$ , which has $2$ different elements.
In the third test case, Euterpe can increase the second, fifth and sixth element to obtain the sequence $1, \underline{2}, 3, 4, \underline{5}, \underline{6}$ , which has $6$ different elements.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted