# Tag Archives: Segment-Tree

## Levelwise Alternating GCD and LCM of nodes in Segment Tree

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 »

## Segment Tree | Set 2 (Range Maximum Query with Node Update)

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

## Count elements which divide all numbers in range L-R

Given N numbers and Q queries, each query consists of L and R. Task is to write a program which prints the count of numbers… Read More »

## Two Dimensional Segment Tree | Sub-Matrix Sum

Given a rectangular matrix M[0…n-1][0…m-1], and queries are asked to find the sum / minimum / maximum on some sub-rectangles M[a…b][e…f], as well as queries… Read More »

## Euler Tour | Subtree Sum using Segment Tree

Euler tour tree (ETT) is a method for representing a rooted tree as a number sequence. When traversing the tree using Depth for search(DFS), insert… Read More »

## Range and Update Query for Chessboard Pieces

Given N pieces of chessboard all being ‘white’ and a number of queries Q. There are two types of queries : Update : Given indices… Read More »

## Pairs involved in Balanced Parentheses

Given a string of brackets, task is to find the number of pairs of brackets involved in a balanced sequence in a given range. Examples… Read More »

## Number of primes in a subarray (with updates)

Given an array of N integers, the task is to perform the following two queries: query(start, end) : Print the number of prime numbers in… Read More »

## Levelwise Alternating OR and XOR operations in Segment Tree

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

## Range query for Largest Sum Contiguous Subarray

Given a number N, and Q queries of two types 1 and 2. Task is to write a code for the given query where, in… Read More »

## Leftover element after performing alternate Bitwise OR and Bitwise XOR operations on adjacent pairs

Given an array of N(always a power of 2) elements and Q queries. Every Query consists of two elements index and value.. We need to… Read More »

## Range Queries for Longest Correct Bracket Subsequence

Given a bracket sequence or in other words a string S of length n, consisting of characters ‘(‘ and ‘)’. Find length of the maximum… Read More »

## Sum of Interval and Update with Number of Divisors

Given an array A of N integers. You have to answer two types of queries : 1. Update [l, r] – for every i in… Read More »

## Maximum Occurrence in a Given Range

Given an array of n integers in non-decreasing order. Find the number of occurrences of the most frequent value within a given range. Examples: Input… Read More »

## Maximum Subarray Sum in a given Range

Given an array of n numbers, the task is to answer the following queries: maximumSubarraySum(start, end) : Find the maximum subarray sum in the range… Read More »