You are not logged in. Please login at www.codechef.com to post your questions!

×

Queries Editorial (CRANQRYS) - Cranium 2015

PROBLEM LINK

Contest

DIFFICULTY

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

Link

LINKS

Tutorial
Problems: MKTHNUM FRBSUM

This question is marked "community wiki".

asked 15 Feb '15, 01:10

sanchit_h's gravatar image

6★sanchit_h
24617
accept rate: 0%

edited 15 Feb '15, 01:11

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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