传统题 1000ms 256MiB

C - Made Up

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

C - Made Up

Score : $300$ points

Problem Statement

Given are three sequences of length $N$ each: $A = (A_1, A_2, \dots, A_N)$, $B = (B_1, B_2, \dots, B_N)$, and $C = (C_1, C_2, \dots, C_N)$, consisting of integers between $1$ and $N$ (inclusive).

How many pairs $(i, j)$ of integers between $1$ and $N$ (inclusive) satisfy $A_i = B_{C_j}$?

Constraints

  • $1 \leq N \leq 10^5$
  • $1 \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)$ such that $A_i = B_{C_j}$.


3
1 2 2
3 1 2
2 3 2
4

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


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

All the pairs satisfy the condition.


3
2 3 3
1 3 3
1 1 1
0

No pair satisfies the condition.

2024寒假入门组刷题营(十四)

未参加
状态
已结束
规则
ACM/ICPC
题目
8
开始于
2024-2-14 13:30
结束于
2024-2-14 15:30
持续时间
2 小时
主持人
参赛人数
9