#P1198. [JSOI2008] 最大数
[JSOI2008] 最大数
Description
You are asked to maintain a sequence and support the following two operations:
- Query operation.
Syntax: Q L
Function: Query the maximum number among the last numbers in the current sequence, and output its value.
Constraint: does not exceed the current length of the sequence.
- Insert operation.
Syntax: A n
Function: Add to , where is the answer to the most recent query operation (if no query has been performed yet, then ). Then take the result modulo a fixed constant , and insert the obtained value at the end of the sequence.
Constraint: is an integer (possibly negative) and within the 64-bit signed integer range.
Note: Initially, the sequence is empty and contains no numbers.
Input Format
The first line contains two integers, and , where is the number of operations and is the fixed constant mentioned above.
Each of the next lines contains one string describing a specific operation, with syntax as described above.
Output Format
For each query operation, output the result in order, one per line.
5 100
A 96
Q 1
A 97
Q 1
Q 2
96
93
96
Hint
Constraints
For all testdata, it is guaranteed that , .
Translated by ChatGPT 5
京公网安备 11011102002149号