再加一个参数又能怎
2025-08-21 14:19:03
发布于:江苏
2阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
int n,m,a[MAXN];
int f(int f,int k){
int l=1,r=n,mid,res=-1;
while(l<=r){
mid=(l+r)/2;
if(a[mid]==k){
res=mid;
if(f==-1){
r=mid-1;
}else l=mid+1;
}else if(a[mid]<k){
l=mid+1;
}else r=mid-1;
}
return res;
}
int main() {
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
cin>>m;
while(m--) {
int b;
cin>>b;
cout<<f(-1, b)<<' '<<f(1,b)<<' ';
if(upper_bound(a+1,a+n+1,b)-a>=n)cout<<-1;
else cout<<upper_bound(a+1,a+n+1,b)-a;
cout<<endl;
}
return 0;
}
这里空空如也
有帮助,赞一个