CF1466B.Last minute enhancements
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
阿忒纳乌斯刚刚完成了他最新的音乐作品,并将于明天向雅典人民展示。不幸的是,这段旋律相当单调,极有可能无法获得热烈的反响。
他的乐曲由 n 个音符组成,我们将这些音符视为正整数。一首乐曲的多样性定义为其中所含不同音符的个数。作为音乐的庇护神,欧忒耳佩(Euterpe)守护着作曲家,并在整个新旋律创作过程中给予他们指引。她决定帮助阿忒纳乌斯,通过修改他的乐曲来提升其多样性。
然而,作为一位次要女神,她无法随意更改乐曲。她仅能对乐曲中的每个音符(共 n 个)执行以下两种操作之一:保持该音符不变,或将其值增加 1。
给定一个描述乐曲音符的整数序列,请计算经过上述操作后所能达到的最大多样性。
输入格式
The input consists of multiple test cases. The first line contains an integer t (1≤t≤10000) — 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≤n≤105) denoting the length of the song. The next line contains a sequence of n integers x1,x2,…,xn (1≤x1≤x2≤…≤xn≤2⋅n), describing the song.
The sum of n over all test cases does not exceed 105.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤10000),表示测试用例的数量。随后是 t 个测试用例,每个测试用例由两行描述。
每个测试用例的第一行包含一个整数 n(1≤n≤105),表示歌曲的长度。第二行包含 n 个整数 x1,x2,…,xn(1≤x1≤x2≤…≤xn≤2⋅n),用于描述该歌曲。
所有测试用例的 n 值之和不超过 105。
输出格式
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,3,2,2,6,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 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,2,3,4,5,6, which has 6 different elements.
在第一个测试用例中,欧忒耳佩可以将第二个、第五个和第六个元素增大,得到序列 1,3,2,2,6,7,该序列包含 5 个不同的元素(增大的元素已加下划线)。
在第二个测试用例中,欧忒耳佩可以将第一个元素增大,得到序列 5,4,该序列包含 2 个不同的元素。
在第三个测试用例中,欧忒耳佩可以将第二个、第五个和第六个元素增大,得到序列 1,2,3,4,5,6,该序列包含 6 个不同的元素。
输入解题思路,AI测评打分。不知道怎么写?