Range Queries with Mo's Algorithm and Block Decomposition

Problem Statement Given a sequence of length n: S1, S2, S3, ..., Sn, process T queries. Each query provides four integers l, r, a, b. For all indices i ∈ [l, r], answer two questions: Count of positions where Si ∈ [a, b] Number of distinct values among Si that satisfy Si ∈ [a, b] Constraints: n ≤ 10^5, T ≤ 10^6 Analysis of Failed Approaches A ...

Posted on Wed, 03 Jun 2026 18:04:59 +0000 by saraadmin

Advanced Data Structures for Competitive Programming Challenges

Problem 1: Subtree Color Dominance This problem requires finding the most frequent color in each subtree. A naive approach uses Mo's algorithm on the Euler tour of the tree combined with a segment tree tracking color frequencies. The Euler tour flattens the tree into an array where each subtree corresponds to a contiguous range. However, the op ...

Posted on Fri, 29 May 2026 20:36:42 +0000 by rahish