310054: CF1776H. Beppa and SwerChat

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Beppa and SwerChat

题目描述

Beppa and her circle of geek friends keep up to date on a group chat in the instant messaging app SwerChat $ ^{\text{TM}} $ . The group has $ n $ members, excluding Beppa. Each of those members has a unique ID between $ 1 $ and $ n $ . When a user opens a group chat, SwerChat $ ^{\text{TM}} $ displays the list of other members of that group, sorted by decreasing times of last seen online (so the member who opened the chat most recently is the first of the list). However, the times of last seen are not displayed. Today, Beppa has been busy all day: she has only opened the group chat twice, once at 9:00 and once at 22:00. Both times, she wrote down the list of members in the order they appeared at that time. Now she wonders: what is the minimum number of other members that must have been online at least once between 9:00 and 22:00? Beppa is sure that no two members are ever online at the same time and no members are online when Beppa opens the group chat at 9:00 and 22:00.

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains an integer $ t $ ( $ 1 \leq t \leq 10\,000 $ ) — the number of test cases. The descriptions of the $ t $ test cases follow. The first line of each test case contains an integer $ n $ ( $ 1 \leq n \leq 10^5 $ ) — the number of members of the group excluding Beppa. The second line contains $ n $ integers $ a_1, \, a_2, \, \dots, \, a_n $ ( $ 1 \le a_i \le n $ ) — the list of IDs of the members, sorted by decreasing times of last seen online at 9:00. The third line contains $ n $ integers $ b_1, \, b_2, \, \dots, \, b_n $ ( $ 1 \le b_i \le n $ ) — the list of IDs of the members, sorted by decreasing times of last seen online at 22:00. For all $ 1\le i < j\le n $ , it is guaranteed that $ a_i \ne a_j $ and $ b_i \ne b_j $ . It is also guaranteed that the sum of the values of $ n $ over all test cases does not exceed $ 10^5 $ .

输出格式


For each test case, print the minimum number of members that must have been online between 9:00 and 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

说明

In the first test case, members $ 4, 5 $ must have been online between 9:00 and 22:00. In the second test case, it is possible that nobody has been online between 9:00 and 22:00.

Input

题意翻译

B和她的怪胎朋友在某个社交软件上的聊天群聊天。 这个聊天群有包括B在内的n名成员,每个成员都有自己从1-n的独特id。 最近使用这个聊天群的成员将会在列表最上方,接下来较次使用聊天软件的成员将会在列表第二名,依次类推。 B会在上午9点和晚上22点登录,并记录这时的列表。 B确保同一时间只有一个人登录,并且在九点和22点并没有其他人登录。 请你输出在9-22点之间的一种成员登录过的最小数量。

Output

**贝帕和SwerChat**

**题目描述**
贝帕和她的极客朋友们在即时通讯应用SwerChat™上保持群聊更新。

这个群除了贝帕之外有n个成员,每个成员都有一个唯一的ID,介于1到n之间。当一个用户打开群聊时,SwerChat™会显示该群其他成员的列表,按照上次在线的时间降序排列(也就是说,最近打开群聊的用户会排在列表的第一位)。然而,上次在线的时间不会显示。

今天,贝帕一整天都很忙:她只打开过两次群聊,一次在9:00,一次在22:00。每次,她都记下了那时出现的成员列表。现在她在想:在9:00到22:00之间至少有多少其他成员必须在线过?

贝帕确信没有两个成员会在同一时间在线,也没有成员在贝帕在9:00和22:00打开群聊时在线。

**输入输出格式**

**输入格式**
每个测试包含多个测试案例。第一行包含一个整数t(1≤t≤10,000)——测试案例的数量。接下来是t个测试案例的描述。

每个测试案例的第一行包含一个整数n(1≤n≤10^5)——群中除贝帕之外的成员数。

第二行包含n个整数a1, a2, …, an(1≤ai≤n)——在9:00按上次在线时间降序排列的成员ID列表。

第三行包含n个整数b1, b2, …, bn(1≤bi≤n)——在22:00按上次在线时间降序排列的成员ID列表。

对于所有1≤i
还保证所有测试案例中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**
```
2
0
4
0
```

**说明**
在第一个测试案例中,成员4, 5必须在9:00到22:00之间在线过。

在第二个测试案例中,可能没有人在线过。**贝帕和SwerChat** **题目描述** 贝帕和她的极客朋友们在即时通讯应用SwerChat™上保持群聊更新。 这个群除了贝帕之外有n个成员,每个成员都有一个唯一的ID,介于1到n之间。当一个用户打开群聊时,SwerChat™会显示该群其他成员的列表,按照上次在线的时间降序排列(也就是说,最近打开群聊的用户会排在列表的第一位)。然而,上次在线的时间不会显示。 今天,贝帕一整天都很忙:她只打开过两次群聊,一次在9:00,一次在22:00。每次,她都记下了那时出现的成员列表。现在她在想:在9:00到22:00之间至少有多少其他成员必须在线过? 贝帕确信没有两个成员会在同一时间在线,也没有成员在贝帕在9:00和22:00打开群聊时在线。 **输入输出格式** **输入格式** 每个测试包含多个测试案例。第一行包含一个整数t(1≤t≤10,000)——测试案例的数量。接下来是t个测试案例的描述。 每个测试案例的第一行包含一个整数n(1≤n≤10^5)——群中除贝帕之外的成员数。 第二行包含n个整数a1, a2, …, an(1≤ai≤n)——在9:00按上次在线时间降序排列的成员ID列表。 第三行包含n个整数b1, b2, …, bn(1≤bi≤n)——在22:00按上次在线时间降序排列的成员ID列表。 对于所有1≤i

加入题单

上一题 下一题 算法标签: