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 | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | 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 | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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.