QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 110

#8125. 米兰中央车站

Statistiques

Silvia 在米兰中央火车站,她注意到车站有很多站台。她认为站台数量太多了,于是决定检查一下实际上需要多少个站台。

Silvia 还注意到车站有一个有趣的现象:列车的到发时刻表每两天重复一次。此外,时刻表的安排使得所有 $n$ 列火车都在第一天到达车站,并在第二天离开车站。注意,这意味着在所有火车到达之前,没有火车会离开。

车站的站台足够长,可以将所有 $n$ 列火车依次排列在同一个站台上。然而,如果火车 $x$ 先进入站台,然后是火车 $y$,那么火车 $x$ 在火车 $y$ 离开之前不能离开站台。

该插图展示了第二个样例测试中站台上的一种可能的列车时刻表。火车标签“i : ai/bi”表示第 i 列火车在第一天第 ai 个到达车站,并在第二天第 bi 个离开车站。火车 (2 : 1/2) 不能在火车 (4 : 5/1) 之前离开站台。

Silvia 想知道最少需要多少个站台,才能使所有火车都能排列在站台上,且不会出现因为前面有尚未离开的火车而导致某列火车无法离开的情况。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 2 \cdot 10^5$),表示火车的数量。

第二行包含 $n$ 个整数 $a_i$ ($1 \le a_i \le n, a_i \neq a_j$ 对于所有 $i \neq j$),表示第 $i$ 列火车在第一天是第 $a_i$ 个到达车站的。序列 $(a_i)$ 是一个排列。

第三行包含 $n$ 个整数 $b_i$ ($1 \le b_i \le n, b_i \neq b_j$ 对于所有 $i \neq j$),表示第 $i$ 列火车在第二天是第 $b_i$ 个离开车站的。序列 $(b_i)$ 是一个排列。

输出格式

在第一行且仅在第一行输出所需的最少站台数量。

子任务

子任务 分值 数据范围
1 21 $n \le 10$
2 18 所需的最少站台数量为 1 或 2
3 31 $n \le 1\,000$
4 40 无附加限制

样例

输入格式 1

5
3 5 2 4 1
3 2 5 1 4

输出格式 1

2

输入格式 2

5
3 1 2 5 4
4 2 3 1 5

输出格式 2

4

说明

第二个样例的说明: 请查看题目描述中的插图。

输入格式 3

3
3 2 1
1 2 3

输出格式 3

1

说明

第三个样例的说明: 所有火车都可以毫无问题地排列在同一个站台上。

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.