QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 2048 MB Total points: 100

#5650. Beppa 和 SwerChat

Statistics

Beppa 和她的一群极客朋友们通过即时通讯应用 SwerChat™ 在群聊中保持联系。

该群组共有 $n$ 名成员(不包括 Beppa)。每位成员都有一个 $1$ 到 $n$ 之间的唯一 ID。当用户打开群聊时,SwerChat™ 会显示该群组中其他成员的列表,并按最后在线时间从晚到早排序(因此最近打开过聊天记录的成员会排在列表的第一位)。然而,具体的最后在线时间并不会显示。

今天,Beppa 一整天都很忙:她只在 9:00 和 22:00 各打开了一次群聊。在这两次打开时,她都记录下了当时成员出现的顺序。现在她想知道:在 9:00 到 22:00 之间,至少有多少名其他成员上线过?

Beppa 确信没有两名成员会在同一时间上线,且当 Beppa 在 9:00 和 22:00 打开群聊时,没有任何成员在线。

输入格式

每个测试点包含多个测试用例。第一行包含一个整数 $t$ ($1 \le t \le 10\,000$),表示测试用例的数量。接下来是 $t$ 个测试用例的描述。

每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 10^5$),表示除 Beppa 外的群组成员人数。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$),表示 9:00 时成员的 ID 列表,按最后在线时间从晚到早排序。

第三行包含 $n$ 个整数 $b_1, b_2, \dots, b_n$ ($1 \le b_i \le n$),表示 22:00 时成员的 ID 列表,按最后在线时间从晚到早排序。

对于所有 $1 \le i < j \le n$,保证 $a_i \neq a_j$ 且 $b_i \neq b_j$。

同时保证所有测试用例中 $n$ 的总和不超过 $10^5$。

输出格式

对于每个测试用例,输出在 9:00 到 22:00 之间必然上线过的最少成员人数。

样例

样例输入 1

4
5
1 4 2 5 3
4 5 1 2 3
6
1 2 3 4 5 6
1 2 3 4 5 6
8
8 2 4 7 1 6 5 3
5 6 1 4 8 2 7 3
1
1
1

样例输出 1

2
0
4
0

说明

在第一个测试用例中,成员 4 和 5 必然在 9:00 到 22:00 之间上线过。

在第二个测试用例中,有可能在 9:00 到 22:00 之间没有任何人上线。

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.