can anyone give me any idea for this problem.
problem: Shil and Wave seqeunce
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 150 |
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