# Tag Archives: Segment-Tree

## LIS using Segment TreeOctober 21, 2017

You are given an array of integers, you need to find the length of the longest increasing sub-sequence. There can be 4 approaches for solving… Read More »

## Segment tree | Efficient implementationOctober 19, 2017

Let us consider the following problem to understand Segment Trees without recursion. We have an array arr[0 . . . n-1]. We should be able… Read More »

## Maximum prefix-sum for a given rangeOctober 7, 2017

Given an array of n integers and q queries, each query having a range from l to r. Find the maximum prefix-sum for the range… Read More »

## Segment Tree | Set 3 (XOR of given range)June 14, 2017

We have an array arr[0 . . . n-1]. There are two type of queries Find the XOR of elements from index l to r… Read More »

## Merge Sort Tree (Smaller or equal elements in given row range)

Given an array where each element is a vector containing integers in sorted order. The task is to answer following queries: count(start, end, k) :… Read More »

## Reconstructing Segment TreeMay 28, 2017

We are given 2*N – 1 integers. We need to check whether it is possible to construct a Range Minimum Query segment tree for an… Read More »

## Persistent Segment Tree | Set 1 (Introduction)February 10, 2017

Prerequisite : Segment Tree Persistency in Data Structure Segment Tree is itself a great data structure that comes into play in many cases. In this… Read More »

## Querying maximum number of divisors that a number in a given range hasNovember 4, 2016

Given Q queries, of type: L R, for each query you must print the maximum number of divisors that a number x (L <= x… Read More »

## How to prepare for ACM – ICPC?October 4, 2016

ACM ICPC(Association for Computing Machinery – International Collegiate Programming Contest) is a world-wide annual multi-tiered programming contest being organized for over thirteen years. The contest… Read More »

## Count and Toggle Queries on a Binary ArrayOctober 1, 2016

Given a size n in which initially all elements are 0. The task is to perform multiple multiple queries of following two types. The queries… Read More »

## Min-Max Range Queries in ArraySeptember 11, 2016

Given an array arr[0 . . . n-1]. We need to efficiently find the minimum and maximum value from index qs (query start) to qe… Read More »

## Range LCM QueriesJuly 26, 2016

Given an array of integers, evaluate queries of the form LCM(l, r). There might be many queries, hence evaluate the queries efficiently. LCM (l, r)… Read More »

## Longest Common Extension / LCE | Set 3 (Segment Tree Method)July 24, 2016

Prerequisites : LCE(Set 1), LCE(Set 2), Suffix Array (n Log Log n), Kasai’s algorithm and Segment Tree The Longest Common Extension (LCE) problem considers a… Read More »

## Efficiently design Insert, Delete and Median queries on a setJuly 1, 2016

Given an empty set initially and a number of queries on it, each possibly of the following types: Insert – Insert a new element ‘x’.… Read More »

## Smallest Subarray with given GCDJune 13, 2016

Given an array arr[] of n numbers and an integer k, find length of the minimum sub-array with gcd equals to k. Example: Input: arr[]… Read More »