sonthaile2002's blog

By sonthaile2002, history, 7 years ago, In English

You are given an array a of n integers (n <= 1e5, a [i] <= 1e5) and m (m <= 1e4) the query has the form (x, y) meaning that finding the xth largest value is made by y consecutive numbers in array a. please help me solve this problem? Thanks. And sorry because of my poor English.

  • Vote: I like it
  • +6
  • Vote: I do not like it

| Write comment?
»
7 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can you give me an example?

Lets say a ={1.2.3.4.5}

and query: (2,3)

What should the answer be?

»
7 years ago, hide # |
Rev. 3  
Vote: I like it -10 Vote: I do not like it

If I will met this problem in contest I will write in this way

Let's create some array $$$b$$$ where we save pair {$$$ a[i], i $$$} to sort them and save every position of element which largest one in array, and after that we can create simple segment sum tree, and answer for every query $$$x$$$ is position of element and $$$y$$$ is position of element + $$$y$$$ — 1

Upd2: My approach is wrong, I am solving problem for finding x th largest number and add y consecutive numbers

Upd: There is the approach https://ideone.com/7to9IH

Time complexity $$$O(n + mlog(n))$$$

»
7 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

If TL is high enough there is a $$$O(n \cdot m)$$$ solution. For each query just calculate the needed sums and use k-th statistics which works in $$$O(n)$$$.

»
7 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can you provide link to the problem?