Find the ball number (1)
Description
A game is popular in a country. The game rule is: in a pile of balls, each ball has an integer number I (0 <= I <= 100000000), which can be repeated, A random integer K (0 <= k <= 100000100) is used to determine whether the ball number k is in this heap ("yes"; otherwise, "no "), answer the question first to win. One person wants to play this game, but he is very lazy. He hopes that you can help him win.
-
Input
-
The first row has two integers, m, n (0 <= n <= 100000,0 <= m <= 1000000); M indicates that there are m balls in the heap, N indicates that the game is played n times. Next, enter m + n integers. The first m represents the number I of the M balls, and the last n represents the random integer k in each game.
-
Output
-
Output "yes" or "no"
-
Sample Input
-
6 423 34 46 768 343 3432 4 23 343
-
Sample output
-
NONOYESYES
#include <iostream>#include <set>using namespace std;int main(){ set<int>s; int m,n; int aa[1000010]; int a1; cin>>m>>n; for(int i=0;i<m;i++) { cin>>a1; s.insert(a1); } for(int i=0;i<n;i++) cin>>aa[i]; for(int i=0;i<n;i++) { if(s.find(aa[i])!=s.end()) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
Find the ball number (1)