logo Algo Beat Contest
登录 注册

代码

作者: Lemon_zqp 强强  ·  发布于 2026-05-08 23:30:52  ·  最后修改于 2026-05-08 23:32:23
已通过

可以使用 upper_bound 快速实现二分

#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100005];
int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    while (m--) {
        int x;
        cin >> x;
        if (a[n] <= x) {
            cout << "-1" << endl;
        } else {
            cout << upper_bound(a + 1, a + n + 1, x) - a << endl;
        }
    }
    return 0;
}

暂无评论

登录 后即可评论。