Codeforces and Polygon may be unavailable from May 23, 4:00 (UTC) to May 23, 8:00 (UTC) due to technical maintenance. ×

How can I solve query problems like "count the number of different elements in [l, r]" on array?

Revision en3, by nyan101, 2016-11-21 03:15:18

sometimes I saw — unfortunately, I can't remember where I saw that — problems like below. I simplified the statement for clarity.

Problem)

You're given an array A with N elements, (A[0], A[1], ..., A[N-1]). and there are two kinds of queries

  • 1 x y : change A[x] to y

  • 2 l r : count the number of different elements in A[l], A[l+1], ..., A[r].

Condition)

  • 1<=N, Q<=100,000 (Q: total number of queries)

  • 1<=A[i]<=10^9 + 9 (A[i] : integer)

I tried to approach with segment tree but still have no idea.. How can I solve this kind of problems?

Tags algorithm, query, range query, array

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English nyan101 2016-11-21 03:15:18 3
en2 English nyan101 2016-11-21 03:14:11 14
en1 English nyan101 2016-11-21 03:13:44 670 Initial revision (published)