← ~/bài tập
P2004

Count Not Greater

Medium
// Đề bài
Given a sorted array and a value x, output how many elements are less than or equal to x.
// Đầu vào
The first line contains an integer n (1 <= n <= 10^5). The second line contains n integers in non-decreasing order. The third line contains the query value x.
// Đầu ra
A single integer: the count of elements <= x.
// Gợi ý
A binary search (upper bound) answers each query in O(log n).
// Ví dụ
Đầu vào ví dụ
5
1 3 3 5 8
4
Đầu ra ví dụ
3
// Thông tin bài tập
Độ khóMedium
Tỉ lệ chấp nhận70%
Giới hạn thời gian1000 ms
Giới hạn bộ nhớ65536 KB
Được chấp nhận7