CF1765L.Project Manager

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There are nn employees at Bersoft company, numbered from 11 to nn . Each employee works on some days of the week and rests on the other days. You are given the lists of working days of the week for each employee.

There are regular days and holidays. On regular days, only those employees work that have the current day of the week on their list. On holidays, no one works. You are provided with a list of days that are holidays. The days are numbered from 11 onwards, day 11 is Monday.

The company receives kk project offers they have to complete. The projects are numbered from 11 to kk in the order of decreasing priority.

Each project consists of multiple parts, where the ii -th part must be completed by the aia_i -th employee. The parts must be completed in order (i. e. the (i+1)(i+1) -st part can only be started when the ii -th part is completed). Each part takes the corresponding employee a day to complete.

The projects can be worked on simultaneously. However, one employee can complete a part of only one project during a single day. If they have a choice of what project to complete a part on, they always go for the project with the highest priority (the lowest index).

For each project, output the day that project will be completed on.

输入格式

The first line contains three integers n,mn, m and kk ( 1n,m,k21051 \le n, m, k \le 2 \cdot 10^5 ) — the number of employees, the number of holidays and the number of projects.

The ii -th of the next nn lines contains the list of working days of the ii -th employee. First, a single integer tt ( 1t71 \le t \le 7 ) — the number of working days. Then tt days of the week in the increasing order. The possible days are: "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday".

The next line contains mm integers h1,h2,,hmh_1, h_2, \dots, h_m ( 1h1<h2<<hm1091 \le h_1 < h_2 < \dots < h_m \le 10^9 ) — the list of holidays.

The jj -th of the next kk lines contains a description of the jj -th project. It starts with an integer pp ( 1p21051 \le p \le 2 \cdot 10^5 ) — the number of parts in the project. Then pp integers a1,a2,,apa_1, a_2, \dots, a_p ( 1axn1 \le a_x \le n ) follow, where pip_i is the index of the employee that must complete the ii -th part.

The total number of parts in all projects doesn't exceed 21052 \cdot 10^5 .

输出格式

Print kk integers — the jj -th value should be equal to the day the jj -th project is completed on.

输入输出样例

  • 输入#1

    3 5 4
    2 Saturday Sunday
    2 Tuesday Thursday
    4 Monday Wednesday Friday Saturday
    4 7 13 14 15
    5 1 1 3 3 2
    3 2 3 2
    5 3 3 3 1 1
    8 3 3 3 3 3 3 3 3

    输出#1

    25 9 27 27
首页