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 | 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 |
# | 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 | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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 .