QOJ.ac

QOJ

時間限制: 10 s 記憶體限制: 1024 MB 總分: 100

#3110. 猜骆驼

统计

Jaap、Jan 和 Thijs 在参加完 2015 年摩洛哥 ACM ICPC 全球总决赛后去沙漠旅行。旅行中包含了一次骑骆驼活动,回到营地后,向导邀请他们参加当晚举行的一场大型骆驼比赛。他们骑过的骆驼也将参赛,并且人们习惯于对比赛结果进行下注。

最有趣的赌注之一是猜测骆驼完成比赛的完整顺序。这种赌注的回报率最高,因为它也是最难猜对的。

Jaap、Jan 和 Thijs 已经下好了注,但比赛还要一个小时才开始,所以他们感到很无聊。他们开始好奇他们有多少对骆驼的预测顺序是一致的。如果骆驼 $c$ 在 Jaap、Jan 和 Thijs 的赌注中都排在骆驼 $d$ 之前,这意味着他们三个人对 $c$ 和 $d$ 的相对顺序预测是一致的。你能帮他们计算有多少对骆驼满足这种情况吗?

输入格式

输入包含: 一行一个整数 $n$ ($2 \le n \le 200\,000$),表示骆驼的数量; 一行 $n$ 个整数 $a_1, \dots, a_n$ ($1 \le a_i \le n$,对于所有 $i$),表示 Jaap 的赌注。其中 $a_1$ 是 Jaap 赌注中第一名的骆驼,$a_2$ 是第二名,以此类推; 一行 Jan 的赌注,格式与 Jaap 的相同; 一行 Thijs 的赌注,格式与 Jaap 的相同。

骆驼编号为 $1, \dots, n$。每只骆驼在每个赌注中恰好出现一次。

输出格式

输出在所有 3 个赌注中出现顺序相同的骆驼对数。

Jaap、Jan 和 Thijs 骑骆驼(顺序不分先后)。摄影:Tobias Werth,采用 cc by-sa 协议。

样例

样例输入 1

3
3 2 1
1 2 3
1 2 3

样例输出 1

0

样例输入 2

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

样例输出 2

3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.