二分上界
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
// 二分求下界:在有序数组a[l..r]中查找首个>=x的位置
int lowerbound(int a[], int l, int r, int x) {
int ans = r + 1; // 默认未找到,返回r+1
while (l <= r) {
int mid = (l + r) / 2; // 取中间位置
if (a[mid] >= x) { // 中间值>=x,可能为答案
ans = mid; // 更新候选答案
r = mid - 1; // 继续向左半区查找更小的下标
} else {
l = mid + 1; // 中间值<x,必须向右半区查找
}
}
return ans; // 返回最终答案
}
int main() {
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
while (q--) {
int target;
cin >> target;
cout << lowerbound(a, 1, n, target) << endl; // 输出下界位置
}
return 0;
}