免费题解随意复制粘贴,后果概不负责
2023-09-11 17:19:13
发布于:江苏
2阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100005] = {-1};
int ans[100005];
void func(int x){
int low = lower_bound(a + 1, a + n + 1, x) - a;
int high = upper_bound(a + 1, a + n + 1, x) - a - 1;
int next = upper_bound(a + 1, a + n + 1, x) - a;
if(next > n){
next = -1;
}
if(a[low] != x){
low = -1;
}
if(a[high] != x){
high = -1;
}
cout << low << ' ' << high << ' ' << next << endl;
return;
}
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
cin >> m;
int temp;
for(int i = 1; i <= m; i++){
cin >> ans[i];
}
for(int i = 1; i <= m; i++){
func(ans[i]);
}
}
这里空空如也
有帮助,赞一个