Find the ball number (ii)
-
Describe
A
-
game is popular in a country. The rules of the game are: in the existing pile of balls, each ball has an integer number I (0<=i<=100000000), the number can be duplicated, there is an empty box, there are two kinds of action: one is "ADD", which means to put M (0<m<=100) ball into an empty box, The other is "QUERY", which means to say M (0<m<=100) a random integer ki (0<=ki<=100000100), respectively, to determine whether the ball numbered Ki is in the empty box allele (exists as "YES", otherwise "NO"), the first to answer the winner. Now there is a man who wants to play the game, but he is very lazy. He wants you to help him win.
-
-
Input
-
The
-
first line has an integer n (0<n<=10000);
Then there are n rows;
Each row may appear in any of the following forms:
The first type:
A string "ADD" followed by an integer m, followed by M i;
The second type:
A string "QUERY" followed by an integer m, followed by a M ki;
-
-
Output
-
-
outputs the result of each query "YES" or "NO".
-
-
Sample input
-
-
2ADD 5 343 6 2QUERY 4 34 54 33 66
-
-
Sample output
-
Yesyesnono
#include <cstdio>#include<cstring>#include<vector>#include<Set>#include<algorithm>using namespacestd;inta[3300500];voidAddintN) { intx=n/ +; A[X]|=(1<< (n% +));}BOOLQueryintN) { intx=n/ +; return(A[x]>> (n% +)) &1;}intMain () {intN; Chart[6]; scanf ("%d",&N); while(n--) { intnum; scanf ("%s%d",t,&num); if(t[0]=='A') while(num--) { inttt; scanf ("%d",&TT); Add (TT); } Else while(num--) { inttt; scanf ("%d",&TT); Query (TT)? puts ("YES"):p UTS ("NO"); } } return 0;}
Nyoj 138 Find the ball number (ii)