#abc202c. C - Made Up

C - Made Up

Score : 300300 points

问题描述

已知三个长度均为 NN 的序列:A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N)B=(B1,B2,,BN)B = (B_1, B_2, \dots, B_N) 以及 C=(C1,C2,,CN)C = (C_1, C_2, \dots, C_N),其中包含的整数都在 11NN(包括两端点)之间。

有多少对整数 (i,j)(i, j) 满足 1i,jN1 \leq i, j \leq N 并且满足 Ai=BCjA_i = B_{C_j}

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Given are three sequences of length NN each: A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N), B=(B1,B2,,BN)B = (B_1, B_2, \dots, B_N), and C=(C1,C2,,CN)C = (C_1, C_2, \dots, C_N), consisting of integers between 11 and NN (inclusive).

How many pairs (i,j)(i, j) of integers between 11 and NN (inclusive) satisfy Ai=BCjA_i = B_{C_j}?

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1Ai,Bi,CiN1 \leq A_i, B_i, C_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_N

B1B_1 B2B_2 \ldots BNB_N

C1C_1 C2C_2 \ldots CNC_N

Output

Print the number of pairs (i,j)(i, j) such that Ai=BCjA_i = B_{C_j}.

Sample Input 1

3
1 2 2
3 1 2
2 3 2

Sample Output 1

4

Four pairs satisfy the condition: (1,1),(1,3),(2,2),(3,2)(1, 1), (1, 3), (2, 2), (3, 2).

Sample Input 2

4
1 1 1 1
1 1 1 1
1 2 3 4

Sample Output 2

16

All the pairs satisfy the condition.

Sample Input 3

3
2 3 3
1 3 3
1 1 1

Sample Output 3

0

No pair satisfies the condition.

update @ 2024/3/10 09:14:27