Array | Range Queries Last Updated : 26 Sep, 2023 The array range query problem can be defined as follows: Given an array of numbers, the array range query problem is to build a data structure that can efficiently answer queries of a particular type mentioned in terms of an interval of the indices. The specific query can be of type – maximum element in the given range, most frequent element in the given range or queries like these. Types of Array Range Queries: Array range queries can be classified based on the type of input provided and on the type of output: Based on the type of input: The value of interest is completely determined by the problem, in this case, the query consists of only a range of indices. A single value of interest is provided in the query. The query consists of a threshold where all the values above or below the threshold are of interest. The query consists of an exact threshold value. Based on the type of output: Returns a single value matching the criteria. Index of an element that matches the criteria provided in the query. A list of all values that satisfy the given criteria. Only a response like “yes” or “no” denoting if there is any result matching the criteria of the query. Some practice problems on Array range Queries: Easy: Range sum queries without updates Range Queries for Frequencies of array elements Range LCM Queries Count Primes in Ranges Queries for number of distinct elements in a subarray Mean of range in array Check in binary array the number represented by a subarray is odd or even Total numbers with no repeated digits in a range Queries for counts of array elements with values in given range Queries for decimal values of subarrays of a binary array GCDs of given index ranges in an array Queries on probability of even or odd number in given ranges Intermediate: Difference Array | Range update query in O(1) Range sum query using Sparse Table Number of indexes with equal elements in given range Constant time range add operation on an array Number whose sum of XOR with given array range is maximum Number of primes in a subarray (with updates) Print modified array after executing the commands of addition and subtraction Sum of Interval and Update with Number of Divisors Queries on XOR of greatest odd divisor of the range Print modified array after multiple array range increment operations Binary array after M range toggle operations Hard: Sparse Table MO’s Algorithm Sqrt (or Square Root) Decomposition Technique | Set 1 (Introduction) Range Minimum Query (Square Root Decomposition and Sparse Table) Number of elements less than or equal to a given number in a given subarray Number of elements less than or equal to a given number in a given subarray | Set 2 (Including Updates) Array range queries over range queries Array range queries for searching an element Maximum Occurrence in a Given Range Merge Sort Tree for Range Order Statistics Count and Toggle Queries on a Binary Array Min-Max Range Queries in Array Range Query on array whose each element is XOR of index value and previous element Count elements which divide all numbers in range L-R Queries for GCD of all numbers of an array except elements in a given range XOR of numbers that appeared even number of times in given Range Quick Links : ‘Practice Problems’ on Arrays ‘Quizzes’ on Arrays ‘Video Tutorials’ on Arrays Share your thoughts in the comments Add Your Comment Please Login to comment...