fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. #define MAX_N 100000
  6. int n, m, input;
  7. int num[MAX_N];
  8. bool find_m(int start, int end) {
  9. int center = (end + start) / 2;
  10. //printf("start : %d , end : %d, center : %d\n", start, end, center);
  11. if (input == num[center])
  12. return true;
  13. else if (end == start)
  14. return false;
  15. else if (input < num[center])
  16. return find_m(start, center - 1);
  17. else if (input > num[center])
  18. return find_m(center + 1, end);
  19. }
  20.  
  21. int main() {
  22. cin.tie(NULL);
  23. ios_base::sync_with_stdio(false);
  24.  
  25. cin >> n;
  26. for (int i = 0; i < n; i++) {
  27. cin >> num[i];
  28. }
  29.  
  30. sort(num, num + n);
  31.  
  32. cin >> m;
  33. for (int i = 0; i < m; i++) {
  34. cin >> input;
  35. if (find_m(0, n - 1))
  36. cout << 1 << '\n';
  37. else
  38. cout << 0 << '\n';
  39. }
  40. }
  41.  
  42. /*
  43. 0 1 2 3 4 5 6 7 8 9
  44.   c
  45. 0 1 2 3 5 6 7 8 9
  46.   c c
  47.   5 6 8 9
  48. c c
  49. */
Time limit exceeded #stdin #stdout 5s 4400KB
stdin
2
2 3
1
1
stdout
Standard output is empty