Problem: 610D - Vika and Segments
can not understand the solution in editorial
can anyone give me any idea of solution in deails???
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 150 |
Problem: 610D - Vika and Segments
can not understand the solution in editorial
can anyone give me any idea of solution in deails???
Name |
---|
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.