CF1139E.Maximize Mex

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn students and mm clubs in a college. The clubs are numbered from 11 to mm . Each student has a potential pip_i and is a member of the club with index cic_i . Initially, each student is a member of exactly one club. A technical fest starts in the college, and it will run for the next dd 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 dd days. Thus, every day the director chooses such team, that the team strength is maximized.

The mex of the multiset SS is the smallest non-negative integer that is not present in SS . For example, the mex of the {0,1,1,2,4,5,9}\{0, 1, 1, 2, 4, 5, 9\} is 33 , the mex of {1,2,3}\{1, 2, 3\} is 00 and the mex of \varnothing (empty set) is 00 .

输入格式

The first line contains two integers nn and mm ( 1mn50001 \leq m \leq n \leq 5000 ), the number of students and the number of clubs in college.

The second line contains nn integers p1,p2,,pnp_1, p_2, \ldots, p_n ( 0pi<50000 \leq p_i < 5000 ), where pip_i is the potential of the ii -th student.

The third line contains nn integers c1,c2,,cnc_1, c_2, \ldots, c_n ( 1cim1 \leq c_i \leq m ), which means that ii -th student is initially a member of the club with index cic_i .

The fourth line contains an integer dd ( 1dn1 \leq d \leq n ), number of days for which the director wants to know the maximum possible strength of the team.

Each of the next dd lines contains an integer kik_i ( 1kin1 \leq k_i \leq n ), which means that kik_i -th student lefts their club on the ii -th day. It is guaranteed, that the kik_i -th student has not left their club earlier.

输出格式

For each of the dd days, print the maximum possible strength of the team on that day.

输入输出样例

  • 输入#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 33 leaves their club. Now, the remaining students are 11 , 22 , 44 and 55 . We can select students 11 , 22 and 44 to get maximum possible strength, which is 33 . Note, that we can't select students 11 , 22 and 55 , as students 22 and 55 belong to the same club. Also, we can't select students 11 , 33 and 44 , since student 33 has left their club.

On the second day, student 22 leaves their club. Now, the remaining students are 11 , 44 and 55 . We can select students 11 , 44 and 55 to get maximum possible strength, which is 11 .

On the third day, the remaining students are 11 and 55 . We can select students 11 and 55 to get maximum possible strength, which is 11 .

On the fourth day, the remaining student is 11 . We can select student 11 to get maximum possible strength, which is 11 .

On the fifth day, no club has students and so the maximum possible strength is 00 .

首页