Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

Help needed in this problem: Count number of good triplets

Revision en1, by aeonary, 2022-10-03 11:52:55

Problem: give an array A of N (1 <= N <= 2 * 10^6) integer. Find the number of good triplets (i, j, k), where i, j, k are all distinct indices such that 1 <= i < j < k <= N. A good triplet (i, j, k) is a triplet such that A[i] = x, A[j] = y, A[k] = z(x, y, z are given numbers).

Example 1:

Input: 5

1 2 2 1 2

1 2 1

Output:

2

Explanation: two triplets are (1,2,4) and (1,3,4)

Example 2:

Input:

5

1 2 2 1 2

2 1 1

Output:

0

Explanation: there are no good triplets

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English aeonary 2022-10-03 11:52:55 564 Initial revision (published)