Problem Solving with Arman (ML+Algo)
Ссылка
нажмите — покажем
нажмите — покажем
Mo's algorithm is an efficient offline query-processing technique based on Square Root (sqrt) Decomposition. It is designed to answer multiple range queries [L, R] on a static array in an optimized order, achieving an overall time complexity ofO((N + Q) * sqrt(N)), where N is the number of elements and Q is the number of queries.
Popularized by Chinese competitive programmer Mo Tao, the algorithm allows you to solve range query problems that cannot easily be solved using standard segment trees or Fenwick trees (such as finding the number of distinct elements or the most frequent element in a range).
CP Algo Article: https://cp-algorithms.com/data_structures/sqrt_decomposition.html
CF Blog about Mo's algorithm: https://codeforces.com/blog/entry/81716
LC Problem to practice: https://leetcode.com/problems/valid-k-unique-subarrays-i
#algorithms #notes
1 · 49 ·