1 条题解

  • 0
    @ 2025-10-14 9:20:06
    #include <bits/stdc++.h>
    using namespace std;
    int n, m;
    int a[1000020];
    int main() {
        cin >> n >> m;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < m; i++) {
            int cnt;
            cin >> cnt;
            int idx = 0;
            for (int j = 20; j >= 0; j--) {
                if (idx + (1 << j) < n) {
                    if (a[idx + (1 << j)] < cnt) {
                        idx += (1 << j);
                    }
                }
            }
            if (a[idx + 1] == cnt) {
                cout << idx + 1 << ' ';
            } else {
                cout << -1 << ' ';
            }
        }
        return 0;
    }
    
    • 1

    信息

    ID
    1282
    时间
    1000ms
    内存
    256MiB
    难度
    (无)
    标签
    (无)
    递交数
    0
    已通过
    0
    上传者