Editorial for Kaninho tập đếm với xâu


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.

Hint 1: Với mỗi \(i\), hãy tìm \(j\) lớn nhất mà \(S[i..j]\) thỏa mãn điều kiện đề bài.

Hint 2: Có thể tìm được \(j\) bằng cách nào?

Hint 3: Làm sao để kiểm tra \(S[i..j]\) thỏa mãn điều kiện?


Lời giải:

Chúng ta sẽ dùng kỹ thuật 2 con trỏ để xử lý bài toán này. Hai con trỏ \(i, j\) sẽ lưu vị trí mà \(S[i..j]\) thỏa mãn điều kiện. Trong quá trình di chuyển hai con trỏ, cần lưu mảng \(cnt[a..z]\) là số lần xuất hiện của mỗi ký tự trong xâu con hiện tại.

Đô phức tạp: \(O(n)\)



Comments

There are no comments at the moment.