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)
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
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)
Название |
---|
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 .