Description1: Add a new programmer to the character set S, whose code is x, to ensure that X does not exist in the current collection. 2: Ask the programmer's MoD Y minimum value in the current character collection. (why count this.) Because there are so many people who have saved the world, they can only take the mold.
Input The first behavior is separated by a space of a positive integer N. Then there are N rows, if the first character of the line is "A", then the action 1, if "B", the Operation 2, where for 100% of the data: n≤100000, 1≤x,y≤300000, to ensure that the second action 1.
Output for operation 2, each line outputs a valid answer.
Sample Input 5
A 3
A 5
B 6
A 9
B 4
Sample Output 3
1
HINT
"Sample description"
In the third row before the operation, the collection has 3, 52 symbols, at this time mod 6 the smallest value is 3 mod 6 = 3;
In the fifth row before the operation, the collection has 3, 5, 9, at this time mod 4 the smallest value is 5 mod 4 = 1;
The question: First divides the inquiry into y greater than sqrt (300000), and y is less than sqrt (300000),
Use an array to record the answer to 1-SQRT (300000). The direct output is when you encounter such an inquiry.
For inquiries larger than sqrt (300000), we deal with them offline. Change the dots to the point of deletion.
Each query is equivalent to asking the number of times in the current set of multiples greater than Y or Y and the nearest distance.
The deletion point obviously can be used and the collection processing, the space is connected together (with the flower God traveled all countries).
Code:
#include <iostream> #include <cstdio> #include <cstring> #define N 300010 #define SN using namespace s
td struct Use{int Kind,k,ans;}
Q[n];
int n,mn[sn+10],f[n],fa[n];
Char ch[5]; inline int find (int x) {if (x!=fa[x]) Fa[x]=find (fa[x]), return fa[x];} int main () {scanf ("%d", &n); for (int i=1;i<=
300001;i++) Fa[i]=i;memset (Mn,127/3,sizeof (MN));
for (int i=1;i<=n;i++) {scanf ("%s%d", &CH,&Q[I].K); q[i].kind=ch[0]-' A ';
if (q[i].kind==0) {for (int j=1;j<=sn;j++) mn[j]=min (mn[j],q[i].k%j); f[q[i].k]=1;}
if (Q[I].KIND==1&&Q[I].K<=SN) Q[I].ANS=MN[Q[I].K];
} for (int i=1;i<=300000;i++) if (!f[i]) fa[i]=i+1;
for (int i=n;i>=1;i--) {if (q[i].kind==0) fa[q[i].k]=q[i].k+1;
else{int T,mi (N); if (Q[I].K>SN) {for (int j=0;j<=300000;j+=q[i].k) {t=find (j,1)), if (t<=300000) mi=min (Mi,t%q[i].
k);
} Q[i].ans=mi; }}} for (int i=1;i<=n;i++) if (q[i].kind) PRINTF ("%d\n", Q[i].ans); }