题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int M = 100100;
int num[M];
int n, q, k, Mid;
bool flag = true;
void f(int r, int l)
{
if(r > l) return;
int mid = (r + l) / 2;
if(num[mid] > k){
l = mid - 1;
f(r, l);
}
else if(num[mid] < k){
r = mid + 1;
f(r, l);
}
else{
flag = false;
Mid = mid;
return;
}
}
void F(int Num)
{
if(flag){
cout << -1 << ' ' << -1 << endl;
return;
}
int r = Num, l = Num;
while(num[r] == num[Num]) r -- ;
while(num[l] == num[Num]) l ++ ;
cout << r + 1 << ' ' << l - 1 << endl;
}
int main()
{
cin >> n >> q;
for(int i = 0; i < n; i ++ ) cin >> num[i];
sort(num, num + n);
for(int i = 0; i < q; i ++ ){
flag = true;
cin >> k;
f(0, n -1);
F(Mid);
}
return 0;
}