题目描述
blablabla
样例
#include<stdio.h>
#include<stdlib.h>
int main() {
int n, q;
int array[100010];
scanf("%d%d", &n, &q);
for (int i = 0;i < n;i++) {
int temp;
scanf("%d", &temp);
array[i] = temp;
}
while (q--) {
int temp;
int left = 0, right = n - 1;
scanf("%d", &temp);
while (left < right) {
int mid = (left + right) / 2;
if (array[mid] >= temp)
right = mid;
else
left = mid + 1;
}
if (array[left] != temp)
printf("-1 -1\n");
else {
printf("%d", left);
int l = 0, r = n - 1;
while (l < r) {
int mid = (l + r+1) / 2;
if (array[mid] <= temp)
l = mid;
else
r = mid - 1;
}
printf(" %d\n", l);
}
}
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla