luogu#P2174. 小Z的神奇数列
小Z的神奇数列
Background
Xiao Z has been studying sequences. He wants to know, for the sequence he studies, what the maximum number is (Max), what the minimum number is (Min), what Max to the power of Min (Max^Min) is, and what the product of all numbers is. Of course, such questions are no problem for Xiao Z. However, he recently had a sudden idea to explore deeper properties of this sequence, so he decided to keep deleting some numbers from the sequence and study the current sequence after each deletion. Since the sequence has many terms, this causes a lot of trouble for Xiao Z, so he asks you to write a program to perform the following operations.
Problem Description
You need to maintain a multiset that supports five operations:
D xDelete ; it is guaranteed that exists. If there are multiple occurrences, delete only one.BQuery the maximum value in the set.SQuery the minimum value in the set.MLet the maximum be and the minimum be ; query .TQuery the product of all numbers, modulo .
For all queries, the multiset is guaranteed to be non-empty.
Input Format
The first line contains two positive integers , the initial multiset size and the number of operations.
The second line contains positive integers , the initial multiset.
Then lines follow, each describing one operation.
Output Format
For each query, output one integer per line representing the answer.
3 6
2 6 9
M
D 9
B
S
M
T
81
6
2
36
12
Hint
Constraints
For partial testdata, , , .
For of the testdata, , .
Translated by ChatGPT 5