There is an empty rectangle of size
where
We cover the rectangles k times from (u1, v1) to (u2, v2), where
The question is: How many squares of that rectangle have been covered ?
№ | Пользователь | Рейтинг |
---|---|---|
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 |
There is an empty rectangle of size
where
We cover the rectangles k times from (u1, v1) to (u2, v2), where
The question is: How many squares of that rectangle have been covered ?
Название |
---|
Don't try to find the state of the rectangle at the end, but rather count how many more squares have been covered after every operation considering all previous operations.
The 400 implies that it is a $$$O(n^3)$$$ solution, we should do something whith each one of the rects $$$n^2$$$ times.
How to find the contribution for the third rect?
Let $$$cells(r_i)$$$ be number of cells in ith rect. Then contribution of first rect equals $$$cells(r_1)$$$. Second is $$$cells(r_2)-cells(intersection(r_1, r_2))$$$
Then it gets interesting. Third is $$$cells(r_3) - cells(intersection(r_3, r_1)) - cells(intersection(r_2, r_1)) + cells(intersection(r_3, r_2))$$$
So, it turns out adding a next rect is adding an intersection of the new rect and all previusly existing rects (and the intersections of them).
Be careful to give every rect a proper sign to know if the number of intersection cells must be added or subtracted.
Can this approach be called Disjoin Set Union ?
I accidentally read the title of this blog as can someone hit me with this problem