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

- Top 10 Algorithms and Data Structures for Competitive Programming
- Segment Tree | Set 1 (Sum of given range)
- How to prepare for ACM - ICPC?
- Segment Tree | Set 2 (Range Minimum Query)
- Largest Rectangular Area in a Histogram | Set 1
- Lazy Propagation in Segment Tree
- Range Minimum Query (Square Root Decomposition and Sparse Table)
- Segment tree | Efficient implementation
- Find LCA in Binary Tree using RMQ
- Overview of Data Structures | Set 3 (Graph, Trie, Segment Tree and Suffix Tree)
- Min-Max Range Queries in Array
- Range query for Largest Sum Contiguous Subarray
- Maximum Subarray Sum in a given Range
- Persistent Segment Tree | Set 1 (Introduction)
- Range LCM Queries
- Segment Tree | Set 2 (Range Maximum Query with Node Update)
- GCDs of given index ranges in an array
- Heavy Light Decomposition | Set 1 (Introduction)
- Number of primes in a subarray (with updates)
- Segment Tree | Set 3 (XOR of given range)
- Range Queries for Longest Correct Bracket Subsequence
- Efficiently design Insert, Delete and Median queries on a set
- Smallest Subarray with given GCD
- Iterative Segment Tree (Range Maximum Query with Node Update)
- LIS using Segment Tree
- Maximum Occurrence in a Given Range
- Queries to check whether a given digit is present in the given Range
- Maximum prefix-sum for a given range
- Heavy Light Decomposition | Set 2 (Implementation)
- Count elements which divide all numbers in range L-R

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 »

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 »

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

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 »

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 »

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 »