CF1139E.Maximize Mex
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n students and m clubs in a college. The clubs are numbered from 1 to m. Each student has a potential pi and is a member of the club with index ci. Initially, each student is a member of exactly one club. A technical fest starts in the college, and it will run for the next d days. There is a coding competition every day in the technical fest.
Every day, in the morning, exactly one student of the college leaves their club. Once a student leaves their club, they will never join any club again. Every day, in the afternoon, the director of the college will select one student from each club (in case some club has no members, nobody is selected from that club) to form a team for this day's coding competition. The strength of a team is the mex of potentials of the students in the team. The director wants to know the maximum possible strength of the team for each of the coming d days. Thus, every day the director chooses such team, that the team strength is maximized.
The mex of the multiset S is the smallest non-negative integer that is not present in S. For example, the mex of the 0,1,1,2,4,5,9 is 3, the mex of 1,2,3 is 0 and the mex of ∅ (empty set) is 0.
某大学有 n 名学生和 m 个社团。社团编号为 1 到 m。每名学生 i 具有一个潜力值 pi,并属于编号为 ci 的社团。初始时,每名学生恰好属于一个社团。该校即将举办一场为期 d 天的科技节,每天都会举行一场编程竞赛。
每天上午,恰好有一名学生退出其所在社团;一旦学生退出社团,此后将不再加入任何社团。每天下午,校方负责人将从每个社团中各选出一名学生(若某个社团已无成员,则该社团不选人),组成当天编程竞赛的参赛队伍。队伍的“强度”定义为该队伍中所有学生潜力值构成的多重集的 mex(最小缺失非负整数)。负责人希望知道接下来 d 天中每一天所能组成的队伍的最大可能强度。因此,每天负责人都会选择一种组队方式,使得队伍强度最大化。
多重集 S 的 mex 是不在 S 中出现的最小非负整数。例如:集合 {0,1,1,2,4,5,9} 的 mex 是 3,集合 {1,2,3} 的 mex 是 0,空集 ∅ 的 mex 也是 0。
输入格式
The first line contains two integers n and m (1≤m≤n≤5000), the number of students and the number of clubs in college.
The second line contains n integers p1,p2,…,pn (0≤pi<5000), where pi is the potential of the i-th student.
The third line contains n integers c1,c2,…,cn (1≤ci≤m), which means that i-th student is initially a member of the club with index ci.
The fourth line contains an integer d (1≤d≤n), number of days for which the director wants to know the maximum possible strength of the team.
Each of the next d lines contains an integer ki (1≤ki≤n), which means that ki-th student lefts their club on the i-th day. It is guaranteed, that the ki-th student has not left their club earlier.
第一行包含两个整数 n 和 m(1≤m≤n≤5000),分别表示学院中学生的数量和社团的数量。
第二行包含 n 个整数 p1,p2,…,pn(0≤pi<5000),其中 pi 表示第 i 位学生的潜力值。
第三行包含 n 个整数 c1,c2,…,cn(1≤ci≤m),表示第 i 位学生最初属于编号为 ci 的社团。
第四行包含一个整数 d(1≤d≤n),表示校长希望知道团队最大可能实力的天数。
接下来的 d 行中,每行包含一个整数 ki(1≤ki≤n),表示在第 i 天,第 ki 位学生退出其所在社团。保证第 ki 位学生此前未退出过任何社团。
输出格式
For each of the d days, print the maximum possible strength of the team on that day.
对于每一天 d,输出该天团队可能达到的最大实力值。
输入输出样例
输入#1
5 3 0 1 2 2 0 1 2 2 3 2 5 3 2 4 5 1
输出#1
3 1 1 1 0
输入#2
5 3 0 1 2 2 1 1 3 2 3 2 5 4 2 3 5 1
输出#2
3 2 2 1 0
输入#3
5 5 0 1 2 4 5 1 2 3 4 5 4 2 3 5 4
输出#3
1 1 1 1
说明/提示
Consider the first example:
On the first day, student 3 leaves their club. Now, the remaining students are 1, 2, 4 and 5. We can select students 1, 2 and 4 to get maximum possible strength, which is 3. Note, that we can't select students 1, 2 and 5, as students 2 and 5 belong to the same club. Also, we can't select students 1, 3 and 4, since student 3 has left their club.
On the second day, student 2 leaves their club. Now, the remaining students are 1, 4 and 5. We can select students 1, 4 and 5 to get maximum possible strength, which is 1.
On the third day, the remaining students are 1 and 5. We can select students 1 and 5 to get maximum possible strength, which is 1.
On the fourth day, the remaining student is 1. We can select student 1 to get maximum possible strength, which is 1.
On the fifth day, no club has students and so the maximum possible strength is 0.
考虑第一个例子:
第一天,学生 3 离开了他们的社团。此时剩余的学生为 1、2、4 和 5。我们可以选择学生 1、2 和 4,以获得可能的最大强度值 3。注意,我们不能选择学生 1、2 和 5,因为学生 2 和 5 属于同一社团;同样,我们也不能选择学生 1、3 和 4,因为学生 3 已离开其社团。
第二天,学生 2 离开了他们的社团。此时剩余的学生为 1、4 和 5。我们可以选择学生 1、4 和 5,以获得可能的最大强度值 1。
第三天,剩余的学生为 1 和 5。我们可以选择学生 1 和 5,以获得可能的最大强度值 1。
第四天,仅剩学生 1。我们可以选择学生 1,以获得可能的最大强度值 1。
第五天,没有任何社团中还有学生,因此可能的最大强度值为 0。
输入解题思路,AI测评打分。不知道怎么写?