Given 3 permutations of equal lengths n ≤ 105, let's call them A, B and C.
Find number of such i-s that there's no such j, that (Ai > Aj and Bi > Bj and Ci > Cj)
# | 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 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Given 3 permutations of equal lengths n ≤ 105, let's call them A, B and C.
Find number of such i-s that there's no such j, that (Ai > Aj and Bi > Bj and Ci > Cj)
Name |
---|
Let's turn the input into triples Ti = (Ai, Bi, Ci).
Sort the triples into increasing order by Ci.
In addition, we'll make a set of pairs of integers, initially empty. We'll store pairs {Aj, Bj} here, keeping the invariant that there are no two pairs {Aj, Bj} and {Ai, Bi} in the set such that Aj < Ai and Bj < Bi.
Now loop from i = n - 1 to i = 0. At every i, Find from the set the smallest element that is larger than or equal to {Ai, Bi}. Let's say that element is {Aj, Bj}.
Since the pair is larger than equal to {Ai, Bi}, Aj > Ai. Then just check if Bj > Bi. If it is, this i won't be counted, since Tj is larger at all three parts.
Otherwise, we'll increment the result by one, and add {Ai, Bi} to the set. To maintain the invariant, while the largest pair that is smaller than {Ai, Bi} in the set is also smaller in its B-part, we'll remove it. We insert at most n elements into the set, and each element obviously gets removed at most once, so this part doesn't affect the overall complexity.
In the end just output the result. total time complexity is .