can anyone give me any idea for this problem.
problem: Shil and Wave seqeunce
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
can anyone give me any idea for this problem.
problem: Shil and Wave seqeunce
Name |
---|
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.
thank you so much