#P4588. Operations on an Integer

    ID: 17834 Type: Default 1000ms 256MiB

Operations on an Integer

Operations on an Integer

You are given an integer \(x\) with an initial value of \(1\) and are asked to perform \(Q\) operations. There are two types of operations:

  1. Type 1: 1 m - Multiply \(x\) by \(m\). Formally, update \[ x \leftarrow x \times m \] and then output \(x \bmod M\).
  2. Type 2: 2 pos - Reverse a previous multiplication. Let \(m_{pos}\) be the multiplier used in the \(pos\text{-th}\) operation (it is guaranteed that the \(pos\text{-th}\) operation is of Type 1 and each Type 1 operation is reversed at most once). Then update: \[ x \leftarrow \frac{x}{m_{pos}} \] and output \(x \bmod M\).

Note: All operations are performed on the exact integer \(x\) and then the result modulo \(M\) is output.

inputFormat

The first line contains two integers \(Q\) and \(M\) (the number of operations and the modulus). The following \(Q\) lines each contain an operation in one of the following formats:

  • 1 m: Multiply \(x\) by \(m\) and output \(x \bmod M\).
  • 2 pos: Reverse the multiplication of the \(pos\text{-th}\) operation (guaranteed to be of Type 1 and not reversed before) and output \(x \bmod M\).

outputFormat

For each operation, output a single line containing the value of \(x \bmod M\) after the operation.

sample

3 100
1 3
1 2
2 1
3

6 2

</p>