fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void)
  5. {
  6. int n, x, i, high, low, ans ;
  7. int m[1000005] ;
  8. scanf ("%d", &n) ;
  9. for (i = 1 ; i <= n ; i++) {
  10. scanf ("%d", &m[i]) ;
  11. }
  12. scanf ("%d", &x) ;
  13. low = 1 ;
  14. high = m[n] ;
  15. while ( low <= high ) {
  16. ans = (low + high) / 2 + 1 ;
  17. if (m[ans] < x) {
  18. low = ans ;
  19. }
  20. else if ( m[ans] > x ) {
  21. high = ans ;
  22. }
  23. else break ;
  24. }
  25. printf ("%d", ans) ;
  26. getchar() ;
  27. getchar() ;
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 19016KB
stdin
11
1 2 4 4 6 7 8 9 10 11 11
11
stdout
10