#include #include using namespace std;

const int N = 1e6 + 10;

int a[N]; int n, m;

int find(int x) // 二分,二分上界 { int l = 0, r = n + 1; while(l < r) { int mid = l + r + 1 >> 1; if(a[mid] <= x) l = mid; else r = mid - 1; }

return r;

}

int main() { cin >> n >> m; a[0] = -1, a[n + 1] = 1e9 + 10; // 添加两个哨兵,如果数过大,我们返回的值就是n for(int i = 1; i <= n; i ++ ) scanf("%d", &a[i]); sort(a + 1, a + n + 1); // 让序列有序

while(m -- )
{
    int x;
    scanf("%d", &x);

    printf("%d\n", find(x));
}
return 0;

}

0 comments

No comments so far...

Information

ID
260
Time
1000ms
Memory
256MiB
Difficulty
6
Tags
# Submissions
41
Accepted
14
Uploaded By