题目链接 数的范围
本题要求找出一个数在数组中的范围,意思就是找到一个区间,使得这个区间全都是该数。这里使用二分法,先确定左边界,也就是数组中第一次出现该数的位置,如果左边界存在,再去求右边界。细节在代码中有注释
#include<iostream>
using namespace std;
const int maxn = 1e6 + 5;
int num[maxn];
int main(void)
{
int n,m;
scanf("%d%d", &n,&m
题目链接 数的范围
本题要求找出一个数在数组中的范围,意思就是找到一个区间,使得这个区间全都是该数。这里使用二分法,先确定左边界,也就是数组中第一次出现该数的位置,如果左边界存在,再去求右边界。细节在代码中有注释
#include<iostream>
using namespace std;
const int maxn = 1e6 + 5;
int num[maxn];
int main(void)
{
int n,m;
scanf("%d%d", &n,&m