×

Contest

Medium

# PRERQUISITES

Persistent Segment Tree

# SOLUTION

The l values were not given directly in the question to force an online solution to the problem without changing the given order of the queries.

You should refer to the links given below, and solve similar problems to understand persistent segment trees.

In the solution, we maintain an array pos which contains the rightmost occurrence of each element. The persistent segment tree's nth root contains the number of distinct elements in the range [1,n]. Since the segment tree counts only the rightmost occurrence of each element, it allows us to safely split our queries.

# SETTER'S SOLUTION

Tutorial
Problems: MKTHNUM FRBSUM

This question is marked "community wiki".

24617
accept rate: 0%

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,490
×2,558
×1,727
×196
×7
×2

question asked: 15 Feb '15, 01:10

question was seen: 1,999 times

last updated: 15 Feb '15, 01:11