## Count sub-arrays whose product is divisible by k

Given an integer K and an array arr[], the task is to count all the sub-arrays whose product is divisible by K. Examples: Input: arr[]… Read More »

- Counting inversions in an array using segment tree
- Number of subarrays have bitwise OR >= K
- Queries to check whether a given digit is present in the given Range
- Remove minimum elements from either side such that 2*min becomes more than max | Set 2
- Range and Update Sum Queries with Factorial
- Range queries to count 1s in a subarray after flip operations
- Queries for Composite numbers in subarray (With Point Updates)
- Count sub-arrays whose product is divisible by k
- Maximize the summation of numbers in a maximum of K moves in range [L, R]

Given an integer K and an array arr[], the task is to count all the sub-arrays whose product is divisible by K. Examples: Input: arr[]… Read More »

Given an unsorted array, trim the array such that twice of minimum is greater than maximum in the trimmed array. Elements should be removed from… Read More »

Given an array arr[] of N integers and Q queries. Each query consists of 3 integers L, R and K. You can move from index… Read More »

Given an array arr[] and an integer K, the task is to count the number of sub-arrays having bitwise OR ≥ K. Examples: Input: arr[]… Read More »

Given an array of N integers, the task is to perform the following two operations on the given array: query(start, end) : Print the number… Read More »

Given an array arr[] of N integers and number of queries Q. The task is to answer three types of queries. Update [l, r] –… Read More »

Given an array of integers arr, the task is to count the number of inversions in the array. If A[i] > A[j] and i <… Read More »

Given an array ‘arr’ all the numbers of which are initialized to ‘0’ then the array can be updated at any time in the following… Read More »

Pre-requisites: Segment Tree Given an array of digits arr[]. Given a number of range [L, R] and a digit X with each range. The task… Read More »

Given an array arr[0 . . . n-1]. The task is to perform the following operation: Find the maximum of elements from index l to… Read More »

Given an array of N positive integers. The task is to perform the following operations according to the type of query given. 1. Print the… Read More »

We have discussed recursive segment tree implementation. In this post, iterative implementation is discussed. Let us consider the following problem understand Segment Trees. We have… Read More »

Given an array of N numbers and Q queries, each query consists of L and R. We need to write a program that prints the… Read More »

A Levelwise GCD/LCM alternating segment tree is a segment tree, such that at every level the operations GCD and LCM alternate. In other words at… Read More »

Given an array arr[0 . . . n-1]. Find the maximum of elements from index l to r where 0 <= l <= r <=… Read More »