#C5632. Question Tagging System

    ID: 49303 Type: Default 1000ms 256MiB

Question Tagging System

Question Tagging System

You are given a system that maintains associations between questions and tags. The system supports two kinds of operations:

  • ADD: Add a question with a unique question identifier and a set of tags. The input line for this operation is in the format "ADD QID k tag1 tag2 ... tagk", where QID is the question id and k is the number of tags.
  • QUERY: Query the system for all question ids that contain all the specified tags. The input line for this operation is in the format "QUERY k tag1 tag2 ... tagk". The output should be the list of matching question ids in sorted order, or -1 if there is no match.

Formally, for a QUERY operation with tag set \(T\), output the sorted list of question ids \(Q\) such that for every tag \(t \in T\), the question with id \(Q\) has tag \(t\). Use LaTeX formatting for any mathematical expressions, for example, \(Q = \{q \mid \forall t \in T, t \text{ is associated with } q\}\).

inputFormat

The first line of input contains an integer n, the number of operations. The following n lines describe the operations. Each operation is either of the form:

ADD QID k tag1 tag2 ... tagk

or

QUERY k tag1 tag2 ... tagk

All input is read from standard input (stdin).

outputFormat

For each QUERY operation, output a single line with the sorted question ids that satisfy the query, separated by a space. If no question satisfies the query, output -1. The output is printed to standard output (stdout).## sample

5
ADD 1 2 math science
ADD 2 3 math physics chemistry
ADD 3 2 science chemistry
QUERY 2 math science
QUERY 1 chemistry
1

2 3

</p>