Last active
August 26, 2020 23:19
-
-
Save ampulhetadosaber/9ca6124c2ddd8f9b06f1bab379d82709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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