#K88237. Authorized Employees Access

    ID: 37264 Type: Default 1000ms 256MiB

Authorized Employees Access

Authorized Employees Access

Given a building with ( n ) floors and ( m ) elevators, each elevator covers a specific range of floors. There are ( k ) employees, and each employee is authorized to use a subset of these elevators. For a given target floor ( t ), determine which employees can access that floor using at least one of their authorized elevators. An employee is considered authorized if there exists an elevator, among those they can use, whose floor range ( [s, e] ) satisfies ( s \le t \le e ).

The input is 1-indexed for both elevators and employees. Your task is to output a sorted list (in increasing order) of such employee indices.

inputFormat

Input is provided via standard input (stdin) with the following format:

  1. The first line contains four integers: ( n ), ( m ), ( k ), and ( t ) where ( n ) is the number of floors, ( m ) is the number of elevators, ( k ) is the number of employees, and ( t ) is the target floor.

  2. The next ( k ) lines each describe an employee. Each line begins with an integer ( l ) denoting the number of elevators the employee is authorized to use, followed by ( l ) integers representing the 1-indexed elevator indices.

  3. The next ( m ) lines each contain two integers ( s ) and ( e ) representing the starting and ending floor (inclusive) that the corresponding elevator services.

outputFormat

Output to standard output (stdout) a single line containing the sorted (in increasing order) employee indices (1-indexed) of the employees who can access the target floor. The indices should be separated by a space.## sample

10 3 4 7
2 1 2
2 2 3
1 1
1 3
1 5
6 10
3 8
1 2 4