CF1776H.Beppa and SwerChat

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Beppa and her circle of geek friends keep up to date on a group chat in the instant messaging app SwerChatTM^{\text{TM}}.

The group has nn members, excluding Beppa. Each of those members has a unique ID between 11 and nn. When a user opens a group chat, SwerChatTM^{\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.

贝帕和她一群极客朋友在即时通讯应用 SwerChatTM^{\text{TM}} 的群聊中保持联系。

该群组(不含贝帕)共有 nn 名成员,每位成员拥有一个唯一的 ID,取值范围为 11 到 nn。当某用户打开群聊时,SwerChatTM^{\text{TM}} 会显示该群组中其余成员的列表,按“最后在线时间”降序排列(即最近一次打开群聊的成员排在列表首位)。但“最后在线时间”的具体数值不会显示。

今天,贝帕一整天都很忙:她仅在上午 9:00 和晚上 22:00 各打开过一次群聊。每次打开时,她都记录下了当时屏幕上成员出现的顺序。现在她想知道:在 9:00 至 22:00 这段时间内,至少有多少名其他成员必须曾上线过一次?

贝帕确信:任意两名成员不会同时在线;且在贝帕于 9:00 和 22:00 打开群聊的那一刻,没有任何成员在线。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤10 0001 \leq t \leq 10\,000) — the number of test cases. The descriptions of the tt test cases follow.

The first line of each test case contains an integer nn (1≤n≤1051 \leq n \leq 10^5) — the number of members of the group excluding Beppa.

The second line contains nn integers a1, a2, …, ana_1, \, a_2, \, \dots, \, a_n (1≤ai≤n1 \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 nn integers b1, b2, …, bnb_1, \, b_2, \, \dots, \, b_n (1≤bi≤n1 \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≤i<j≤n1\le i \lt j\le n, it is guaranteed that ai≠aja_i \ne a_j and bi≠bjb_i \ne b_j.

It is also guaranteed that the sum of the values of nn over all test cases does not exceed 10510^5.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5),表示除 Beppa 外该组成员的数量。

第二行包含 nn 个整数 a1, a2, …, ana_1, \, a_2, \, \dots, \, a_n(1≤ai≤n1 \le a_i \le n),表示成员 ID 的列表,按其在 9:00 时最后一次在线时间从近到远(即降序)排序。

第三行包含 nn 个整数 b1, b2, …, bnb_1, \, b_2, \, \dots, \, b_n(1≤bi≤n1 \le b_i \le n),表示成员 ID 的列表,按其在 22:00 时最后一次在线时间从近到远(即降序)排序。

对所有满足 1≤i<j≤n1\le i \lt j\le n 的 i,ji,j,保证 ai≠aja_i \ne a_j 且 bi≠bjb_i \ne b_j。

此外,保证所有测试用例中 nn 的总和不超过 10510^5。

输出格式

For each test case, print the minimum number of members that must have been online between 9:00 and 22:00.

对于每个测试用例,输出在 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

说明/提示

In the first test case, members 4,54, 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.

在第一个测试用例中,成员 4,54, 5 必须在 9:00 至 22:00 期间在线。

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

输入解题思路,AI测评打分。不知道怎么写?

首页