#P5568. [SDOI2008] 校门外的区间

[SDOI2008] 校门外的区间

Description

Inspired by the classic problem “Trees Outside the School Gate”, person A, based on basic knowledge of discrete mathematics, abstracts 55 kinds of operations to maintain a set SS (SS is initially empty) and finally output SS. Now, please complete this harder enhanced version of “Trees Outside the School Gate” — “Intervals Outside the School Gate”.

The five operations are:

  • U T: S=STS = S \cup T
  • I T: S=STS = S \cap T
  • D T: S=STS = S - T
  • C T: S=TSS = T - S
  • S T: S=STS = S \oplus T

The basic set operations are defined as follows:

  • ABA \cup B: {xxAxB}\{x \mid x \in A \vee x \in B\}
  • ABA \cap B: {xxAxB}\{x \mid x \in A \wedge x \in B\}
  • ABA - B: {xxAxB}\{x \mid x \in A \wedge x \notin B\}
  • ABA \oplus B: (AB)(BA)(A-B)\cup (B-A).

Input Format

There are MM lines. The first letter of each line describes the operation type, followed by an interval (an interval is written as (a,b), (a,b], [a,b), [a,b]).

Output Format

Output one line containing several intervals representing the set SS. All intervals should be output in increasing order, and there should be exactly one space between two adjacent intervals.

If the set is empty, output empty set.

U [1,5]
D [3,3]
S [2,4]
C (1,5)
I (2,3]
(2,3)

Hint

0a,b65535,M700000 \leq a,b \leq 65535, M \leq 70000.

Translated by ChatGPT 5