Editorial for Tổng đoạn con
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Với mỗi vị trí
, ta đếm số đoạn con
thỏa mãn bài toán. Tiến hành tìm chỉ số
nhỏ nhất thỏa mãn
thông qua Tìm kiếm nhị phân (Binary Search) kết hợp Tổng tiền tố (Prefix Sum). Khi đó các chỉ số
thỏa mãn tổng các phần tử đoạn
không vượt quá
sẽ nằm trong đoạn
.
Độ phức tạp: .
Comments