I was trying to solve subsequences http://mirror.codeforces.com/problemset/problem/597/C of Testing Round #12 but could not figure out the solution.Can anyone explain the solution using binary indexed tree.
# | 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 |
2 | maomao90 | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
I was trying to solve subsequences http://mirror.codeforces.com/problemset/problem/597/C of Testing Round #12 but could not figure out the solution.Can anyone explain the solution using binary indexed tree.
Name |
---|
We will loop from 1 to N and at each step dp[i][j] will be the number of increasing subsequences of length i ending at element with value j. Let's say that the current element is a[i]. Obviously, this is a new subsequence of length 1 ending at a[i]. So we will do ++dp[1][a[i]]. Then for j from 2 to K we will do dp[j][a[i]]+=(dp[j-1][1]+dp[j-1][2]+dp[j][3]+...+dp[j-1][a[i]-1]) since we can extend every subsequence of length j-1 which ends in an element which is less that the current one :)
Here is my submission — http://mirror.codeforces.com/contest/597/submission/14321058 :)
Apologies in advance if revisiting old post is a taboo on code forces.
But I can't help wonder why did my solution resulted in a TLE
http://mirror.codeforces.com/contest/597/submission/18835377
Shouldn't this have the same time complexity with the one just mentioned?
You missed the tree.
Thanks a lot, just googled BIT online. My mind is completely blown now, now I see why some of the code contains weird x&(-x) equations.
bad
yeeeeee
One dumbass little child at our ioi team trainings posted these when my computer was free to get my contribution down. Temotoloraia so just please don't minus.
I made mistake, I'm sorry