#C12000. Employee Schedule Query

    ID: 41380 Type: Default 1000ms 256MiB

Employee Schedule Query

Employee Schedule Query

Given the schedules of employees and a list of queries, determine which employees are available at a given day and time. Each employee's schedule consists of several time blocks specified by a string of days and a time interval. A query consists of a day (represented as a single character) and a time. An employee is considered available for a query if the query's day is included in any of their time blocks and the query's time lies within the corresponding start (inclusive) and end (exclusive) time interval.

Your task is to process the input data and for each query output in a single line the employee indices (1-indexed) in ascending order that are available at the queried time, separated by spaces. If no employee is available, output an empty line.

Note: Time intervals are given in integer hours. The condition for an employee being available during a query with time \( T \) in an interval \([S, E)\) is \( S \le T < E \).

inputFormat

The input is read from standard input (stdin).

Format:
- The first line contains two integers (e) and (q), representing the number of employees and the number of queries, respectively.
- The next (e) groups of lines describe each employee's schedule. For each employee:
    - The first line contains an integer (b), the number of time blocks.
    - Then (b) lines follow, each containing a string (the days available, e.g. MTWRF) and two integers (start hour and end hour), separated by spaces.
- After all employee schedules, there are (q) lines, each describing a query. Each query line contains a day (a single character) and an integer (the time).

outputFormat

The output is printed to standard output (stdout).

For each query, print a single line containing the 1-indexed employee IDs that are available at the query time in ascending order, separated by spaces. If no employee is available for a query, print an empty line.## sample

3 3
2
MTWRF 9 17
S 10 14
1
U 0 24
3
MWF 19 22
TR 9 12
SU 13 18
R 10
U 5
M 20
1 3

2 3

</p>