HINT 1
HINT 2
HINT 3
HINT 1
HINT 2
HINT 3
HINT 4
HINT 1
HINT 2
5A. K-th Number in the Union of Segments
HINT 1
HINT 1
HINT 2
HINT 1
HINT 2
# | 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 |
Binary Search EDU
Average should be in double not int or long long.
Any length is ok as long as the average is maximum.
Try a test case that all number is 0.
It is a DAG so we can use top sort + DP to get shortest path.
Binary search for the average, minus average on every edge.
If the shortest path is <= 0, it means we can have an even lower average. If the shortest path is > 0, it means this average is too high. Note, we don't need to find a path that is exactly 0 cost. Binary search will help us narrow down.
1 might not be the only source, so we need to push all in degree 0 to queue first.
(a+b)/(c+d) > m => a+b > (c+d)*m => a-m*c + b-m*d > 0
Binary search for m.
5A. K-th Number in the Union of Segments
Just follow what theory says
k should be 0 indexed for the theory, so [1, n^2] becomes [0, n^2-1]. Because cnt(x) could return 0, we need k to start from 0, otherwise 1 will be skipped.
There is a trick to get O(n) for cnt(x). Start from bottom left and count towards upper right, if mid > i*j, move j, otherwise move i.
k should be 0 indexed.
Sort both array and use two pointers method for cnt(x). Start from 0 of first array and start from n-1 of second array.
Rev. | Lang. | By | When | Δ | Comment | |
---|---|---|---|---|---|---|
en2 | NaoJoeMiao | 2022-06-06 19:42:35 | 2080 | (published) | ||
en1 | NaoJoeMiao | 2022-06-06 07:58:23 | 413 | Initial revision (saved to drafts) |
Name |
---|