can anyone give me any idea for this problem.
problem: Shil and Wave seqeunce
# | User | Rating |
---|---|---|
1 | jiangly | 3976 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3482 |
8 | hos.lyric | 3382 |
9 | gamegame | 3374 |
10 | heuristica | 3357 |
# | User | Contrib. |
---|---|---|
1 | cry | 168 |
2 | -is-this-fft- | 165 |
3 | atcoder_official | 161 |
3 | Um_nik | 161 |
5 | djm03178 | 157 |
6 | Dominater069 | 156 |
7 | adamant | 154 |
8 | luogu_official | 152 |
9 | awoo | 151 |
10 | TheScrasse | 147 |
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