#K90707. Playlist Query Processor

    ID: 37812 Type: Default 1000ms 256MiB

Playlist Query Processor

Playlist Query Processor

You are given a collection of playlists. Each playlist is a sequence of song IDs. You need to perform several operations on these playlists based on the input queries. There are three types of queries:

  • Query Type 1: 1 i x pos — Insert the song ID x into the i-th playlist at index pos (0-indexed).
  • Query Type 2: 2 i x — Remove the first occurrence of the song ID x from the i-th playlist.
  • Query Type 3: 3 i — Find and output the median song ID of the i-th playlist. The median is defined as follows: Let \(n\) be the number of songs in the playlist and \(A_sorted\) be the sorted order of the playlist. If \(n\) is odd, the median is \(A_{sorted}[\lfloor n/2 \rfloor]\). If \(n\) is even, the median is \(\min(A_{sorted}[n/2 - 1], A_{sorted}[n/2])\).

Process the queries in order. For every query of type 3, print the result in a new line.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. An integer n representing the number of playlists.
  2. For each playlist, a line starting with an integer m indicating the number of songs followed by m integers representing the song IDs.
  3. An integer q representing the number of queries.
  4. q lines follow, each corresponding to a query. The query format varies with the query type as described above.

Note: Playlist indices (i) in queries are 1-indexed, while the position pos for insertion is 0-indexed.

outputFormat

For each query of type 3, output the median song ID (an integer) on a new line to standard output (stdout).

## sample
2
3 1 3 5
4 2 6 7 9
6
1 1 4 2
3 1
2 2 7
3 2
1 1 6 1
3 1
3

6 4

</p>