# Tag Archives: Segment-Tree

## Perform append, update, delete and range sum queries on the given array

Given an array arr[] of size N and the task is to answer Q queries of the following types: 1 X 0: Append X at… Read More »

## Queries for elements greater than K in the given index range using Segment Tree

Given an array arr[] of N elements and a number of queries where each query will contain three integers L, R and K. For each… Read More »

## Find the count of distinct numbers in a range

Given an array of size N containing numbers only from 0 to 63, and you are asked Q queries regarding it. Queries are as follows:… Read More »

## Calculate the Sum of GCD over all subarrays

Given an array of integers, the task is to calculate the sum of GCD of all the subarrays of an array. GCD of an array… Read More »

## Number of subarrays with GCD = 1 | Segment tree

Given an array arr[], the task is to find the count of sub-arrays with GCD equal to 1. Examples: Input: arr[] = {1, 1, 1}… Read More »

## Smallest subarray with GCD as 1 | Segment Tree

Given an array arr[], the task is to find the smallest sub-arrays with GCD equal to 1. If there is no such sub-array then print… Read More »

## Queries for the minimum element in an array excluding the given index range

Given an array arr[] of N integers and Q queries where each query consists of an index range [L, R]. For each query, the task… Read More »

## String Range Queries to find the number of subsets equal to a given String

Given a string S of length N, and M queries of the following type: Type 1: 1 L x, Indicates update Lth index of string… Read More »

## Queries for number of distinct elements in a subarray | Set 2

Given an array arr[] of N integers and Q queries. Each query can be represented by two integers L and R. The task is to… Read More »

## Kth smallest element in a subarray

Given an array arr of size N. The task is to find the kth smallest element in the subarray(l to r, both inclusive). Note :… Read More »

## Flipping Sign Problem | Lazy Propagation Segment Tree

Given an array of size N.There can be multiple queries of the following types. update(l, r) : On update, flip( multiply a[i] by -1) the… Read More »

## Cartesian tree from inorder traversal | Segment Tree

Given an in-order traversal of a cartesian tree, the task is to build the entire tree from it. Examples: Input: arr[] = {1, 5, 3}… Read More »

## Sum of maximum of all subarrays | Divide and Conquer

Given an array arr[] of length N, the task is to find the sum of the maximum elements of every possible sub-array of the array.… Read More »

## Find the number of different numbers in the array after applying the given operation q times

Given an array of size N, initially consists of zeroes only. The task is to apply given operation q times and find the number of… Read More »

## Index of kth set bit in a binary array with update queries

Given a binary array arr[] and q queries of following types: k: find the index of the kth set bit i.e. kth 1 in the… Read More »