Блог пользователя hoang25

Автор hoang25, история, 3 года назад, По-английски

Hello guys, I'm having trouble with a problem.

Given an array A and a number k, find the k-th largest continuous subsequence! I can only think of a brute-force solution using prefix sum, which run in O(n ^ 2). In this problem n could be as large as 1e5. Can anyone give me a hint?

Thanks in advance!

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

Binary search for the answer. Let the answer be x, you can find in $$$O(nlog(n))$$$ time how many elements are greater than or less than that sum using prefix sum. Total complexity $$$O(n*log(n)*log(sum))$$$.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Bin search th answer and uisng segtree and prefix sum to check i guest =))

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

As kindly pointer out by Farhan132, the approach below is terribly wrong. Maybe it could be useful as an exercise to find mistakes in others' solutions :D

As they say, there is always a fast, but wrong solution