#P8667. Count Valid Triplets

    ID: 21833 Type: Default 1000ms 256MiB

Count Valid Triplets

Count Valid Triplets

Given three integer arrays \(A = [A_1, A_2, \cdots, A_N]\), \(B = [B_1, B_2, \cdots, B_N]\), and \(C = [C_1, C_2, \cdots, C_N]\), count the number of triplets \((i, j, k)\) that satisfy the following conditions:

  1. \(1 \le i, j, k \le N\)
  2. \(A_i < B_j < C_k\)

Hint: Sorting the arrays \(A\) and \(C\), and then using binary search to count elements less than or greater than a given value, may help solve the problem efficiently.

inputFormat

The first line contains an integer \(N\) representing the size of each array.
The second line contains \(N\) space-separated integers representing array \(A\).
The third line contains \(N\) space-separated integers representing array \(B\).
The fourth line contains \(N\) space-separated integers representing array \(C\).

outputFormat

Output a single integer representing the number of triplets \((i, j, k)\) that satisfy \(A_i < B_j < C_k\).

sample

3
1 5 6
2 3 4
7 8 9
6

</p>