#P11911. Set Operations and Membership Queries

    ID: 14016 Type: Default 1000ms 256MiB

Set Operations and Membership Queries

Set Operations and Membership Queries

Given two positive integers \(n\) and \(m\), define the universal set \(U = \{1, 2, \ldots, n\}\). We then construct \(n+m\) sets \(A_1, A_2, \ldots, A_{n+m}\) as follows:

  • For \(1 \le i \le n\), set \(A_i = \{j \in U \mid j \text{ is a multiple of } i\}\).
  • For \(n+1 \le i \le n+m\), the set \(A_i\) is defined by an operation determined by a parameter \(op_i\):
    • If \(op_i = 1\), two integers \(x\) and \(y\) are given and \(A_i = A_x \cup A_y\).
    • If \(op_i = 2\), two integers \(x\) and \(y\) are given and \(A_i = A_x \cap A_y\).
    • If \(op_i = 3\), a single integer \(x\) is given and \(A_i = U \setminus A_x\) (i.e. the complement of \(A_x\) in \(U\)).

After constructing the sets, there are \(q\) queries. Each query consists of two positive integers \(x\) and \(y\). For each query, output YES if \(y \in A_x\), otherwise output NO.

inputFormat

The first line contains three integers \(n, m, q\).

Then follow \(m\) lines, each describing an operation for sets \(A_{n+1}\) to \(A_{n+m}\):

  • If the operation type is \(1\) or \(2\), the line contains three integers: \(op\), \(x\), and \(y\).
  • If the operation type is \(3\), the line contains two integers: \(op\) and \(x\).

After the operations, there are \(q\) lines, each containing two integers \(x\) and \(y\) representing a query.

outputFormat

For each query, output a line containing YES if \(y \in A_x\) and NO otherwise.

sample

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

YES NO NO

</p>