P9809 [SHOI2006] Homework Homework
Description
You are given a set $S$, which is initially empty. You need to perform the following two operations a total of $N$ times.
Operation 1: Add a new element to the set $S$, with label $X$. It is guaranteed that $X$ does not exist in the current set.
Operation 2: In the current set $S$, query the minimum value of $a \bmod Y$ among all elements.
Input Format
The first line contains a positive integer $N$.
The next $N$ lines each contain one character and one positive integer. If the character is `A`, this operation is Operation 1. If the character is `B`, this operation is Operation 2.
Output Format
For each Operation 2, output one line containing an integer representing the answer.
Explanation/Hint
For $100\%$ of the testdata, $N \leq 10^5$, $X, Y \leq 3 \times 10^5$. The testdata guarantees that the first operation is Operation 1.
Translated by ChatGPT 5