Please help with this problem from October circuit from Hackerearth. In their editorial they just posted solution code. Please provide some idea(I know that Segment tree can be used) but I am not sure how to handle the reverse operation.
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Please help with this problem from October circuit from Hackerearth. In their editorial they just posted solution code. Please provide some idea(I know that Segment tree can be used) but I am not sure how to handle the reverse operation.
Название |
---|
This Problem helped me in solving this problem — GSS1
Disclaimer: There may be multiple ways to solve this problem. Below I outline my approach during the contest.
Assuming that you can do basic stuff with segment trees, I suggest reading up this article: Answering max subarray range queries
Try the problem on your own for some time after reading up the article. If you don't make much progress, read up the hints in the order till you get to something new which you didn't think of earlier.
Now coming to the reversing part, consider the 3 intervals (or 2 when either of the side ones converge to 0 length) I1: = [1, L - 1], I2: = [L, R] and I3: = [R + 1, N].
For each interval Ik denote by Prek, Sufk, Sumk, maxSubk the max prefix sum, max suffix sum, total sum and the max subarray sum respectively (for 1 ≤ k ≤ 3). ...
Note that reversing interval I2, only swaps the value of Pre2 and Suf2 for it. ...
Then the maximum subarray sum of the array (after I2 has been reversed) will be the maximum of the following 6 possible sums:
maxSub1
maxSub2
maxSub3
max(0, Suf1) + Sum2 + max(0, Pre3)
max(0, Suf1) + max prefix sum of reversed I2 = max(0, Suf1) + Suf2
max suffix sum of reversed I2 + max(0, Pre3) = Pre2 + max(0, Pre3) ...