# Tag Archives: Segment-Tree

## Queries to update a given index and find gcd in range

Given an array arr[] of N integers and queries Q. Queries are of two types: Update a given index ind by X. Find the gcd… Read More »

## Lazy Propagation in Segment Tree | Set 2

Given an array arr[] of size N. There are two types of operations: Update(l, r, x) : Increment the a[i] (l <= i <= r)… Read More »

## 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 »

## Remove minimum elements from either side such that 2*min becomes more than max | Set 2

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

## Maximize the summation of numbers in a maximum of K moves in range [L, R]

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 »

## Number of subarrays have bitwise OR >= K

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 »

## Queries for Composite numbers in subarray (With Point Updates)

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 »

## Range and Update Sum Queries with Factorial

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 »

## Counting inversions in an array using segment tree

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 »

## Range queries to count 1s in a subarray after flip operations

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 »

## Queries to check whether a given digit is present in the given Range

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 »

## Iterative Segment Tree (Range Maximum Query with Node Update)

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 »

## Queries to find maximum product pair in range with updates

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 »

## Iterative Segment Tree (Range Minimum Query)

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 »

## Count number of smallest elements in given range

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 »