#P1198. [JSOI2008] 最大数

    ID: 198 远端评测题 1000ms 125MiB 尝试: 1 已通过: 0 难度: 6 上传者: 标签>2008线段树二分各省省选江苏

[JSOI2008] 最大数

Description

You are asked to maintain a sequence and support the following two operations:

  1. Query operation.

Syntax: Q L

Function: Query the maximum number among the last LL numbers in the current sequence, and output its value.

Constraint: LL does not exceed the current length of the sequence. (L>0)(L > 0)

  1. Insert operation.

Syntax: A n

Function: Add tt to nn, where tt is the answer to the most recent query operation (if no query has been performed yet, then t=0t = 0). Then take the result modulo a fixed constant DD, and insert the obtained value at the end of the sequence.

Constraint: nn 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, MM and DD, where MM is the number of operations and DD is the fixed constant mentioned above.

Each of the next MM 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 1M2×1051 \leq M \leq 2 \times 10^5, 1D2×1091 \leq D \leq 2 \times 10^9.

Translated by ChatGPT 5