#P2174. Multiset Query Operations
Multiset Query Operations
Multiset Query Operations
You are given an initial multiset of integers and need to perform a series of operations. The multiset supports the following five operations:
D x
: Delete one occurrence of \(x\) from the multiset. It is guaranteed that \(x\) exists in the multiset, and if there are multiple occurrences, only one is removed.B
: Query the maximum value in the multiset.S
: Query the minimum value in the multiset.M
: Let \(a\) be the maximum value and \(b\) be the minimum value in the multiset. Compute \(a^b \bmod 317847191\) (present the formula in LaTeX as \(a^b \bmod 317847191\)).T
: Query the product of all numbers in the multiset modulo \(317847191\).
For each querying operation, it is guaranteed that the multiset is non-empty. You are also given the initial multiset and a series of operations. Your task is to process the operations efficiently and output the answer for each query.
inputFormat
The first line contains two space-separated integers \(n\) and \(q\) (\(1 \le n, q \le 10^5\)), which represent the number of initial elements and the number of operations, respectively.
The second line contains \(n\) space-separated integers representing the initial multiset.
Each of the following \(q\) lines contains an operation in one of the following formats:
D x
B
S
M
T
outputFormat
For each query operation (B
, S
, M
, T
), output the result on a separate line.
sample
5 5
1 2 3 4 5
B
S
M
T
D 3
5
1
5
120
</p>