Editorial for Chuỗi ngọc


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: kieulqd

Xây dựng bảng f[u][v] = số lượng ký tự u đứng trước khí tự v.

Việc dựng bảng f[ ][ ] bằng cách tạo mảng d[S[k]][ ] = vị trí của ký tự S[k] trong dãy S, -> d[S[k]][] là dãy tăng dần.

Với mỗi ký tự S[k] đếm số lượng các ký tự đứng sau nó bằng cách tìm kiếm nhị phân trên mảng d[ ][ ] và lưu vào mảng f[S[k]][ ].

Duyệt các truy vấn ~a_i~~b_i~, cộng dồn kết quả với f[a[i]][b[i]].


Comments

Please read the guidelines before commenting.


There are no comments at the moment.