# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 163 |
4 | TheScrasse | 159 |
5 | nor | 157 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | Petr | 146 |
8 | orz | 146 |
10 | pajenegod | 145 |
Name |
---|
Consider oranges as +1 and apples as -1.
Do the partial sum on the array. Now we want to find for every i , the maximum j such that for each i < = k < = j, partial[k] > = partial[i] .
You can find such j using binary search and RMQ. (This is possible with simple stack too in O(n) ).
For all i (1 <= i <= n) calc the largest p[i] such that for all i <= k <= p[i] count of 'p' in a[i:k] > count of 'j' in a[i:k] it can be done using prefixes and binary search
Similarly, calc s (for all (1 <= i <= n) lowest s[i] such adding fruits from i to s[i] is possible)
Make tree segment on s. Bruteforce left part of line. To find answer which starts in left you need to find the largest t such s[t] <= left for i <= t <= p[left], t can be finded by down search in tree segment
Can you show me Code
https://pastebin.com/V9duKDsD