A15591 | Beppa and SwerChat
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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$ .
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.
In the second test case, it is possible that nobody has been online between 9:00 and 22:00.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted