Editorial for Đếm trong đoạn


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: Yunan

Tiến hành sắp xếp mảng a theo thứ tự tăng dần. Với mỗi truy vấn, gọi i là chỉ số nhỏ nhất thỏa mãn giá trị phần tử lớn hơn hoặc bằng lj là chỉ số lớn nhất thỏa mãn giá trị phần tử nhỏ hơn hoặc bằng r (sử dụng Tìm kiếm nhị phân, có thể sử dụng hàm lower_boundupper_bound). Đáp án của bài toán là số lượng chỉ số nằm trong đoạn [i,j].

Độ phức tạp: O(n.log(n)+q.log(n)).


Comments