This is a question on HackerEarth [Monk and his Friends | Practice Problems]
MY logic is to create a unordered_multiset(for less time complexity) then using set.find() check whether the elements are present in the multiset or not. My solution is not giving TLE but is passing on just on test case…
I could not understand what is the problem or Did I understood question in the wrong way…
Please Help me…
This is my code…
indent preformatted text by 4 spaces//
#include<bits/stdc++.h>
using namespace std;
void solve()
{
long long n,m;
cin>>n>>m;
unordered_multiset<long long> s;
vector<string> vec;
for(int i=0;i<n;i++)
{
long long x;
cin>>x;
s.insert(x);
}
for(int i=n;i<n+m;i++)
{
long long x;
cin>>x;
if(s.find(x)!=s.end()) vec.push_back("YES");
else vec.push_back("NO");
}
for(auto &p:vec) cout<<p<<"\n";
cout<<endl;
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
}