Editorial for Bedao Mini Contest 09 - CNTDIFF
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:
Sử dụng một map để duy trì số lượng số trong một đoạn gồm ~k~ bông hoa. Với mỗi ~i~ ~(i \ge k + 1)~ ta sẽ thực hiện hai thao tác trừ đi số ở vị trí ~i - k~ và cộng map lên số ở vị trí ~i~. Với mỗi thao tác update, xét nếu số đó xuất hiện đúng ~1~ lần thì số lượng số khác nhau nhiều nhất tăng lên ~1~, hoặc ngược lại nếu số đó không còn tồn tại trong map.
Độ phức tạp: ~O(NlogN)~
Comments