Skip to content

Instantly share code, notes, and snippets.

@ampulhetadosaber
Last active August 26, 2020 23:19
Show Gist options
  • Save ampulhetadosaber/9ca6124c2ddd8f9b06f1bab379d82709 to your computer and use it in GitHub Desktop.
Save ampulhetadosaber/9ca6124c2ddd8f9b06f1bab379d82709 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
int N, Q, VETOR[100050], X;
int main()
{
cin >> N >> Q;
for(int i = 1; i <= N; i++) cin >> VETOR[i];
for(int i = 1; i <= Q; i++)
{
cin >> X;
int ini = 1, fim = N, meio;
bool achou = false;
while(fim >= ini)
{
meio = (ini + fim)/2;
if(X < VETOR[meio]) fim = meio - 1;
if(X > VETOR[meio]) ini = meio + 1;
if(X == VETOR[meio])
{
achou = true;
break;
}
}
if(achou) cout << "S\n";
else cout << "N\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment