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

Автор Tanmoy1228, история, 9 лет назад, По-английски

can anyone give me any idea for this problem.

problem: Shil and Wave seqeunce

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

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

dp[i][0]=number of wave seq where a[i] is the last element and the one before him is lower(<)

dp[i][1]=number of wave seq where a[i] is the last element and the one before him is bigger(>)

Now to get the answer you maintain 2 BITs (for < and >).For every BIT you update for an element a[j] at position a[j] with dp[j][0](for the first BIT) and dp[j][1] (for second). To get the answer for dp[j][0] you query the second BIT(>) in interval [1,a[j]-1] and for dp[j][1] you query first BIT(<) in interval [a[j]+1,max_val].

Actually for a query,you want to link a[j] to all sequence from before that respect some conditions,that's why for dp[j][0] we want to link a[j] with an element smaller [1,a[j]-1] and that has been linked to a bigger element (we do query on BIT >).

Also take care that you have to add 1 to dp[j][0] and dp[j][1] as a[j] single can do a wave seq(in theory,for making sequences of length>1,you have to start with 1).

The answer is in the sum of all dp[i][0/1] — 1. Hope I helped.