D. Matryoshkas

time limit per test

2 seconds

memory limit per test

256 megabytes

Matryoshka is a wooden toy in the form of a painted doll, inside which you can put a similar doll of a smaller size.

A set of nesting dolls contains one or more nesting dolls, their sizes are consecutive positive integers. Thus, a set of nesting dolls is described by two numbers: s --- the size of a smallest nesting doll in a set and m --- the number of dolls in a set. In other words, the set contains sizes of s,s+1,...,s+m−1 for some integer s and m (s,m>0).

You had one or more sets of nesting dolls. Recently, you found that someone mixed all your sets in one and recorded a sequence of doll sizes --- integers a1,a2,...,an.

You do not remember how many sets you had, so you want to find the minimum number of sets that you could initially have.

For example, if a given sequence is a=2,2,3,4,3,1. Initially, there could be 2 sets:

  • the first set consisting of 4 nesting dolls with sizes 1,2,3,4;
  • a second set consisting of 2 nesting dolls with sizes 2,3.

According to a given sequence of sizes of nesting dolls a1,a2,...,an, determine the minimum number of nesting dolls that can make this sequence.

Each set is completely used, so all its nesting dolls are used. Each element of a given sequence must correspond to exactly one doll from some set.

Input

The first line of input data contains a single integer t (1≤t≤104) --- the number of test cases.

The description of the test cases follows.

The first line of each test case contains one integer n (1≤n≤2⋅105) --- the total number of matryoshkas that were in all sets.

The second line of each test case contains n integers a1,a2,...,an (1≤ai≤109) --- the sizes of the matryoshkas.

It is guaranteed that the sum of values of n over all test cases does not exceed 2⋅105.

Output

For each test case, print one integer k --- the minimum possible number of matryoshkas sets.

Example

Input

Copy

复制代码

10

6

2 2 3 4 3 1

5

11 8 7 10 9

6

1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

8

1 1 4 4 2 3 2 3

6

1 2 3 2 3 4

7

10 11 11 12 12 13 13

7

8 8 9 9 10 10 11

8

4 14 5 15 6 16 7 17

8

5 15 6 14 8 12 9 11

5

4 2 2 3 4

Output

Copy

复制代码
2
1
6
2
2
2
2
2
4
3

Note

The first test case is described in the problem statement.

In the second test case, all matryoshkas could be part of the same set with minimum size s=7.

In the third test case, each matryoshka represents a separate set.

解题说明:此题是一道数学题,将一个数列拆分为多个连续递增数列,确保拆分后的数列中每个数只出现一次。先统计出数列中每个数字出现的个数,然后对数列进行排序,根据统计的个数找出子序列。

cpp 复制代码
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int a[2000020];
map<int, int>cnt;
main()
{
	int T;
	cin >> T;
	while (T--)
	{
		int n;
		cin >> n;
		cnt.clear();
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i];
			cnt[a[i]]++;
		}
		sort(a + 1, a + n + 1);
		int ans = 0;
		for (int i = 1; i <= n; i++)
		{
			if (cnt[a[i]])
			{
				int now = a[i];
				while (cnt[now])
				{
					cnt[now]--;
					now++;
				}
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
相关推荐
Fox爱分享1 小时前
字节二面:1000瓶酒,有一瓶是毒药,多少只老鼠可以查出来?
算法·面试·程序员
+wacyltd大模型备案算法备案1 小时前
大模型评估测试题库怎么建?风险分类、测试样本的完整方法
人工智能·算法·安全·分类·大模型·大模型备案·大模型上线登记
Fox爱分享1 小时前
字节二面智力题:100只老虎和1只羊关在一起,这只羊会不会被吃?
算法·面试·程序员
xin(n_n)b2 小时前
经典题目(3):把数字翻译成字符串;兑换零钱
算法
惊鸿一博2 小时前
特征匹配+Glue Factory 框架评估特征提取与匹配算法时常用的度量标准
算法·特征匹配
柒和远方2 小时前
LeetCode 4. 寻找两个正序数组的中位数 —— 二分划分的艺术
javascript·python·算法
z小猫不吃鱼3 小时前
模型剪枝经典论文精读:Channel Pruning for Accelerating Very Deep Neural Networks
算法·机器学习·剪枝
njsgcs3 小时前
已知链中心距用节数算中间电机摆放位置 常量弧长 三链轮弦长模型算法
算法
2601_962440844 小时前
计算机毕业设计之jsp旅游网站管理系统
java·开发语言·算法·课程设计·旅游·推荐算法
池塘的蜗牛5 小时前
AFDM波形基于DFT的通感一体化
算法