Problem: 610D - Vika and Segments
can not understand the solution in editorial
can anyone give me any idea of solution in deails???
№ | Пользователь | Рейтинг |
---|---|---|
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 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Problem: 610D - Vika and Segments
can not understand the solution in editorial
can anyone give me any idea of solution in deails???
Название |
---|
First of all, break up the problems into rectangles of two types. One those which are horizontal, and the other which are horizontal. Now there are 3 types of events:
The events of type 1 and 2 can easily be taken care of using a stack, and merging the two rectangles into a single longer one. For the events of type 3, imagine you're looking at the plane and run your gaze through it from left to right, Whenever you see such an intersection you subtract the area from your answer. Also you need to use Coordinate compression.
This is essentially what we do. We move from left to right, keeping track of the rectangles currently in the x coordinate, and check for intersections. We could do this using a set, but because finding distance between iterators takes O(n) time, that would make our solution O(2·n2). To reduce this runtime, we use a BIT to keep track of them, and doing so makes our runtime O(2·n lgn)
Update: You could read more on line sweep algorithms here and here.
My submission is this: 15129127, it's definitely slightly messy but it should help.
Please point out any errors/inaccuracies, as I solved the problem some time back.