题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度分析:blablabla
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度分析:blablabla
C++ 代码
blablabla
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
int n,q;
int a[100010];
int lower_find(int x)//找到第一小于x的下标
{
int L = 0,R = n -1;
while(L[HTML_REMOVED]>1;
if(a[mid] < x)L = mid ;
else R = mid -1;
}
return L;
}
int up_find(int x)//找到第一个大于x的下标
{
int L = 0,R = n -1;
while(L[HTML_REMOVED]>1;
if(a[mid] > x)R = mid;
else L = mid + 1;
}
return R;
}
int main()
{
cin >>n >> q;
for(int i =0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
while(q--)
{
int m;
cin >> m;
if(m > a[n-1]) cout << "-1 -1"<<endl;
else
{
int x =lower_find(m)+1;
int y = up_find(m) -1;
if(m == a[0])x=0;//边界判断
if(m == a[n-1])y=n-1;//边界判断
if(x>y)cout<<"-1 -1"<<endl;
else
{
cout<<x <<' '<<y<<endl;
}
}
}
return 0;
}