fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int n,k,s=0;
  5. long long b[100002],a[100002];
  6. cin>>n>>k;
  7. for(int i=0; i<n; i++) {
  8. cin>>a[i];
  9. }
  10. for (int j=0; j<k; j++) {
  11. cin>>b[j];
  12. }
  13. int l;
  14. int r;
  15. int m;
  16. for (int i=0; i<k; i++) {
  17. l=0;
  18. r=n-1;
  19. while (l<r) {
  20. m=(l+r)/2;
  21. if (b[i]>a[m]) {
  22. l=m+1;
  23. }
  24. else if (b[i]<a[m]) {
  25. r=m;
  26. }
  27. if (b[i]==a[m]) {
  28. cout<<"YES"<<endl;
  29. s++;
  30. l=r;
  31. }
  32. }
  33. if (a[0]==b[i] && n==1) {
  34. cout<<"YES"<<endl;
  35. }
  36. else if (s==0) {
  37. cout<<"NO"<<endl;
  38. }
  39. s=0;
  40. }
  41. return 0;
  42. }
  43.  
  44.  
  45.  
  46.  
Success #stdin #stdout 0s 4912KB
stdin
10 5
1 2 3 4 5 6 7 8 9 10 
-2 0 1 9 12
stdout
NO
NO
YES
YES
NO