CF1519C.Berland Regional
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarp is an organizer of a Berland ICPC regional event. There are n universities in Berland numbered from 1 to n. Polycarp knows all competitive programmers in the region. There are n students: the i-th student is enrolled at a university ui and has a programming skill si.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer k, each university will send their k strongest (with the highest programming skill s) students in the first team, the next k strongest students in the second team and so on. If there are fewer than k students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is 0.
Help Polycarp to find the strength of the region for each choice of k from 1 to n.
Polycarp 是 Berland 地区 ICPC 区域赛的组织者。Berland 共有 n 所大学,编号从 1 到 n。Polycarp 熟悉该地区所有参与竞赛编程的学生。共有 n 名学生:第 i 名学生就读于大学 ui,其编程能力为 si。
Polycarp 现在需要确定比赛规则,尤其是每支队伍的成员人数。
Polycarp 知道,若他将每支队伍的人数设定为某个整数 k,则每所大学将依次派出其编程能力 s 最高的 k 名学生组成第一支队伍,再派出剩余学生中能力最高的 k 名组成第二支队伍,依此类推。若剩余学生不足 k 人,则无法组成下一支队伍。注意:可能存在某些大学最终未派出任何队伍。
该地区的总实力定义为所有已组建队伍中所有队员能力值之和。若未组建任何队伍,则总实力为 0。
请帮助 Polycarp 计算当 k 分别取 1 到 n 时,该地区的总实力。
输入格式
The first line contains a single integer t (1≤t≤1000) — the number of testcases.
The first line of each testcase contains a single integer n (1≤n≤2⋅105) — the number of universities and the number of students.
The second line of each testcase contains n integers u1,u2,…,un (1≤ui≤n) — the university the i-th student is enrolled at.
The third line of each testcase contains n integers s1,s2,…,sn (1≤si≤109) — the programming skill of the i-th student.
The sum of n over all testcases doesn't exceed 2⋅105.
第一行包含一个整数 t(1≤t≤1000)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 大学数量,同时也是学生数量。
每个测试用例的第二行包含 n 个整数 u1,u2,…,un(1≤ui≤n)—— 第 i 个学生所就读的大学编号。
每个测试用例的第三行包含 n 个整数 s1,s2,…,sn(1≤si≤109)—— 第 i 个学生的编程能力值。
所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each testcase print n integers: the strength of the region — the total skill of the members of the present teams — for each choice of team size k.
对每个测试用例,输出 n 个整数:即对于每个团队规模 k 的选择,该区域的实力(即当前所有队伍成员的技能总和)。
输入输出样例
输入#1
4 7 1 2 1 2 1 2 1 6 8 3 1 5 1 5 10 1 1 1 2 2 2 2 3 3 3 3435 3014 2241 2233 2893 2102 2286 2175 1961 2567 6 3 3 3 3 3 3 5 9 6 7 9 7 1 1 3083
输出#1
29 28 26 19 0 0 0 24907 20705 22805 9514 0 0 0 0 0 0 43 43 43 32 38 43 3083
说明/提示
In the first testcase the teams from each university for each k are:
- k=1:
- university 1: [6],[5],[5],[3];
- university 2: [8],[1],[1];
- k=2:
- university 1: [6,5],[5,3];
- university 2: [8,1];
- k=3:
- university 1: [6,5,5];
- university 2: [8,1,1];
- k=4:
- university 1: [6,5,5,3];
在第一个测试用例中,每个大学对于每个 k 所组成的队伍如下:
- k=1:
- 大学 1:[6],[5],[5],[3];
- 大学 2:[8],[1],[1];
- k=2:
- 大学 1:[6,5],[5,3];
- 大学 2:[8,1];
- k=3:
- 大学 1:[6,5,5];
- 大学 2:[8,1,1];
- k=4:
- 大学 1:[6,5,5,3];
输入解题思路,AI测评打分。不知道怎么写?