0分求助!!!(lower_bound)
查看原帖
0分求助!!!(lower_bound)
1014678
yang_h_x_2012楼主2024/4/28 21:30

0分

#include <bits/stdc++.h>
using namespace std;
int a[1000000];

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	while (m--) {
		int x;
		cin >> x;
		if (upper_bound(a, a + n, x) != lower_bound(a,  a + n, x)) {
			cout << lower_bound(a,  a + n, x) - a+1 << " ";

		} else {
			cout << -1;
		}

	}

	return 0;
}

2024/4/28 21:30
加载中...