Codeforces 1642B Power Walking

B. Power Walking

Sam is a kindergartener, and there are nn children in his group. He decided to create a team with some of his children to play "brawl:go 2".

Sam has nn power-ups, the ii-th has type aiai. A child's strength is equal to the number of different types among power-ups he has.

For a team of size kk, Sam will distribute all nn power-ups to kk children in such a way that each of the kk children receives at least one power-up, and each power-up is given to someone.

For each integer kk from 11 to nn, find the minimum sum of strengths of a team of kk children Sam can get.

Input

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤3⋅1051≤t≤3⋅105) — the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤3⋅1051≤n≤3⋅105).

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — types of Sam's power-ups.

It is guaranteed that the sum of nn over all test cases does not exceed 3⋅1053⋅105.

Output

For every test case print nn integers.

The kk-th integer should be equal to the minimum sum of strengths of children in the team of size kk that Sam can get.

Example

input

Copy

2
3
1 1 2
6
5 1 2 2 2 4

output

Copy

2 2 3 
4 4 4 4 5 6 

题意 :  会给你n个技能,你要将n个技能分别依次分配给k个同学(1 <= k <= n,分配k次),然后你分配给这些同学最少的技能种数之和是多少。


样例解释:

5 1 2 2 2 4

首先你要将所有的技能分配给一个同学,有四种不同的技能,那么你只一次输出 4(因为有四种不同的技能)

然后你又要将所有技能重新分配给两个同学,那么我们最好的分配就是(2,2,2,4,5)(1),这样答案就是 4 ,如果你这样分(1,2,2,4,5)(2),那么这样的答案就为 显然不符合题意。

 


题解:首先我们要做的是统计有多少不同种类的数(假如有m个不同种类的数字),那么前1~m个同学的最优解肯定就是我们的m(因为我们可以尽可能地把相同的一种技能给到一个人,然后给到其他人的技能种数就会少一些),前面的操作保证了我们每一个同学的技能种类不会有重复,然后(m+1~n)个同学肯定能会出现重复的技能,所以我们就在m的基础上依次加一即可。

remark:尽可能让重重复的技能给到一个人


#include 

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair PII;

const int N = 3e5 + 10;

int n, ans, t;
int arr[N];

void solve()
{
     mapmp;
     cin >> n;
     int cnt1 = 0, cnt2 = 1;
     for(int i = 1; i <= n; i ++){
          cin >> arr[i];
          mp[arr[i]]++;
          if(mp[arr[i]] == 1) cnt1++;//种类数
          //if(mp[arr[i]] > 1) cnt2++;//重复数
     }
     for(int i = 1; i <= cnt1; i ++)
          cout << cnt1 << " ";
     int temp = 1;
     for(int i = cnt1+1; i <= n; i ++){
          cout << cnt1+temp << " ";
          temp++;
     }
     cout << endl;
     mp.clear();
}

int main()
{
     IOS;
     cin >> t;
     while(t--)
          solve();
     return 0;
}

你可能感兴趣的:(c++)