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 | 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 | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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.
The idea is to do a topsort on just directed edges, if there is a loop, then output NO.
If three is no loop, we can always find a solution. All we need to do is make sure the direction we add is following the top sort order.
So we assign an id for topsort results and use this determine which should come first.
You can view this question as adding more edges to a DAG and not creating loops, how to add those edges?
Things I learned:
Use scanf printf and puts instead of cin/cout.
memset is costly, not O(1). Avoid at all cost.
Use BFS to do top sort instead of DFS to avoid stack overflow.
Name |
---|