Editorial for DIVISORPART


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.

Đặt fi=0 nếu ai1 là ước của aifi=i nếu ai1 không phải là ước của ai. Suy ra. Si=maxj=1ifi

Xây dựng segment tree mà mỗi node trong cây lưu giá trị max fi trong đoạn node đó quản lý. Như vậy ta có thể dễ dàng tính được Si thông qua segment tree.

Khi thay đổi giá trị của ai, chỉ có fifi+1 là có thể thay đổi do đó ta chỉ cần cập nhật lại 2 vị trí này trong segment tree.

Độ phức tạp: O(n·log2n)


Comments

Please read the guidelines before commenting.


There are no comments at the moment.