fork download
  1. var i,n,m,y,g:longint;
  2. a:array[-1..1000008]of longint;
  3. procedure qsort(l,r:longint);
  4. var c,t,i,j:longint;
  5. begin
  6. if l>=r then exit;
  7. c:=(l+r) div 2;
  8. i:=l; j:=r;
  9. repeat
  10. while (a[i]<a[c]) do inc(i);
  11. while a[j]>a[c] do dec(j);
  12. if i<=j then
  13. begin
  14. if i<j then
  15. begin t:=a[i]; a[i]:=a[j]; a[j]:=t; end;
  16. inc(i); dec(j);
  17. end;
  18. until i>j;
  19. qsort(l,j); qsort(i,r);
  20. end;
  21. function tknp(x:longint):longint;
  22. var k,l,r:longint;
  23. begin
  24. l:=1; r:=n;
  25. while l<=r do
  26. begin
  27. g:=(l+r) div 2;
  28. if a[g]>x then r:=r-1
  29. else begin k:=g ; l:=g+1; end;
  30. end;
  31. exit(k);
  32. end;
  33. begin
  34. //assign(input,'CLIMBSTAIR.inp') ; reset(input);
  35. //assign(output,'CLIMBSTAIR.OUT') ; rewrite(output);
  36. readln(n,m);
  37. for i:=1 to n do
  38. read(a[i]);
  39. qsort(1,n);
  40. // for i:=1 to n do writeln(a[i]);
  41. readln();
  42. for i:=1 to m do
  43. begin
  44. read(y);
  45. writeln(tknp(y));
  46. end;
  47. close(input); close(output);
  48. end.
Success #stdin #stdout 0s 5476KB
stdin
5 2
1 2 2 4 5
2 4
stdout
3
4