{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\"text/x-mathjax-config\"\u003eMathJax.Hub.Config({messageStyle:\"none\",tex2jax:{skipTags:[\"script\",\"noscript\",\"style\",\"textarea\",\"code\"],inlineMath:[[\u0027$\u0027,\u0027$\u0027]]},delayStartupUntil:\"onload\"});\u003c/script\u003e\n\u003cscript src\u003d\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config\u003dTeX-MML-AM_CHTML\"\u003e\u003c/script\u003e\n\u003chtml\u003e\n \u003chead\u003e\u003c/head\u003e\n \u003cbody\u003e\n \u003cp\u003e蒜头君手上有个长度为 $n$ 的数组 $A$。由于数组实在太大了,所以蒜头君也不知道数组里面有什么数字,所以蒜头君会经常询问在数组 $A$ 中,小于等于 $x$ 的最大值是多大?\u003c/p\u003e \n \u003ch3 id\u003d\"-\"\u003e输入格式\u003c/h3\u003e \n \u003cp\u003e第一行输入两个整数 $n$ 和 $m$,分别表示数组的长度和查询的次数。\u003c/p\u003e \n \u003cp\u003e接下来一行有 $n$ 个整数 $a_i$。\u003c/p\u003e \n \u003cp\u003e接下来 $m$ 行,每行有 $1$ 个整数 $x$,表示蒜头君询问的整数。\u003c/p\u003e \n \u003ch3 id\u003d\"-\"\u003e输出格式\u003c/h3\u003e \n \u003cp\u003e对于每次查询,如果可以找到,输出这个整数。\u003c/p\u003e \n \u003cp\u003e否则输出 $-1$。\u003c/p\u003e \n \u003ch3 id\u003d\"-\"\u003e数据范围\u003c/h3\u003e \n \u003cp\u003e$1 \\le n, m \\le 10^5, 0 \\le x \\le 10^6$。\u003c/p\u003e \n \u003c/body\u003e\n\u003c/html\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e10 5\n1 1 1 2 3 5 5 7 8 9\n0\n1\n4\n9\n10\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e-1\n1\n3\n9\n9\u003c/pre\u003e"}},{"title":"","value":{"format":"HTML","content":" \u003cpre\u003e二分查找的意思是将数组里的数每次分开一半来查找\n \u003cpre\u003e比如:1 2 3 4 5 6 要查找5这个数\n \u003cpre\u003e第一次查找是(0+(6-1))/2 \u003d2(因为是下标所以减1),因为5\u003e3所以可以判断这个数在右边\n \u003cpre\u003e第二此查找下标就变成2—5,之后的意思同上\n \u003cpre\u003e也可以用STL里的binary_search(数组名,数组+个数,查找的数)\n \u003cpre\u003eupper_bound(数组名,数组+个数,查找的数)-数组名。如果能找到就返回第一个大于这个数的下标,否则返回你数组加的个数的下标\n \u003crpe\u003ehttps://www.cnblogs.com/wkfvawl/p/9475939.html不明白的话可以看下这个"}}]}