Hello everyone. I am really stuck at this problem, can you please provide a solution? Problem Link : Overlapping Boxes. Thanks in advance :).
Problem Source : TCS Mockvita 2
# | 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 |
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 |
Hello everyone. I am really stuck at this problem, can you please provide a solution? Problem Link : Overlapping Boxes. Thanks in advance :).
Problem Source : TCS Mockvita 2
Name |
---|
Hint sweep line technique
Let's move across the x-axis from 0 to $$$MAX_X = 1e4$$$ and maintain the values of the $$$x$$$-th coloumn from the grid. We need to recalculate it efficiently using the $$$x-1$$$-th coloumn somehow. If there is no rectangle having $$$x$$$ as a leftmost or rightmost point, its clear that $$$x$$$-th coloumn is equal to the $$$x-1$$$-th one. Otherwise there are two possible types of actions for $$$x$$$:
- $$$x$$$ is the rightmost coordinate of the rectangle
- $$$x$$$ is the leftmost coordinate of the rectange
For each action of the first type we need to decrease values in the appropriate range by the appropriate cost value. And for the second type actions we need to increase the values in the same way. To do in efficiently you can construct a preffix array for that values and then add it to the $$$x-1$$$-th coloumn and that is — you've got an $$$x$$$-th coloumn. Then just update the maximum and its count.
Complexity is $$$O(MAX_X * MAX_Y + N)$$$
Here is my brief implementation https://ideone.com/82XDr3 . There might be some bugs, but anyway it can help you understand the idea.