#P5568. The Gates: Advanced Interval Operations

    ID: 18798 Type: Default 1000ms 256MiB

The Gates: Advanced Interval Operations

The Gates: Advanced Interval Operations

Inspired by the classic problem "Trees Outside the Campus Gate", this enhanced challenge focuses on performing set operations on an interval. Initially, an empty set \(S\) is maintained. You will be given a series of operations on \(S\) using basic concepts from discrete mathematics. After processing all operations sequentially, print the final sorted set \(S\) in ascending order.

The operations are defined as follows:

  • U T: \(S = S \cup T\)
  • I T: \(S = S \cap T\)
  • D T: \(S = S - T\)
  • C T: \(S = T - S\)
  • S T: \(S = S \oplus T\)

The basic set operations are defined as:

  • \(A \cup B = \{ x \mid x \in A \vee x \in B \}\)
  • \(A \cap B = \{ x \mid x \in A \wedge x \in B \}\)
  • \(A - B = \{ x \mid x \in A \wedge x \notin B \}\)
  • \(A \oplus B = (A - B) \cup (B - A)\)

Input: The first line is an integer \(n\), the number of operations. Each of the following \(n\) lines describes one operation in the following format:

op m a1 a2 ... am
  • op is one of the characters: U, I, D, C, S.
  • m is the number of elements in the set \(T\).
  • a1, a2, ..., am are the space-separated integers in \(T\).

Output: Output the final sorted set \(S\) (in ascending order) as a list of space-separated integers. If \(S\) is empty, output an empty line.

inputFormat

The input consists of multiple lines:

  1. The first line contains a single integer \(n\), the number of operations.
  2. Each of the next \(n\) lines contains an operation in the format:
op m a1 a2 ... am
  • op: A character among U, I, D, C, S, representing the operation.
  • m: The number of elements in the set \(T\).
  • a1, a2, ..., am: The integers that form the set \(T\).

outputFormat

Output the sorted set \(S\) in ascending order as a sequence of space-separated integers. If \(S\) is empty, output an empty line.

sample

3
U 3 1 2 3
D 1 2
S 2 2 4
1 2 3 4