lower_bound 是返回大于等于x的那个位置;
upper_bound是返回大于x的那个位置;
以上是y总的二分模板;
数的范围:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100100;
int a[N];
int main()
{
int n,m;
cin >> n >> m;
for(int i = 0; i < n ; i++)
cin >> a[i];
while (m -- )
{
int x;
cin >> x;
int lo = lower_bound(a,a+n,x) - a;
int up = upper_bound(a,a+n,x) - a - 1;
if (up < lo) cout << "-1 -1" << endl;
else
cout << lo <<" " << up << endl;
}
}