题库练习 Optical Experiment
← 上一题 下一题 →

A8163 | Optical Experiment

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Professor Phunsuk Wangdu has performed some experiments on rays. The setup for $n$ rays is as follows.

There is a rectangular box having exactly $n$ holes on the opposite faces. All rays enter from the holes of the first side and exit from the holes of the other side of the box. Exactly one ray can enter or exit from each hole. The holes are in a straight line.

![](/uploads/acgo/image/0d1f814527ae7d6e_f334e6114bfb.jpeg)Professor Wangdu is showing his experiment to his students. He shows that there are cases, when all the rays are intersected by every other ray. A curious student asked the professor: "Sir, there are some groups of rays such that all rays in that group intersect every other ray in that group. Can we determine the number of rays in the largest of such groups?".

Professor Wangdu now is in trouble and knowing your intellect he asks you to help him.

输入格式

The first line contains $n$ ( $1<=n<=10^{6}$ ), the number of rays. The second line contains $n$ distinct integers. The $i$ -th integer $x_{i}$ ( $1<=x_{i}<=n$ ) shows that the $x_{i}$ -th ray enters from the $i$ -th hole. Similarly, third line contains $n$ distinct integers. The $i$ -th integer $y_{i}$ ( $1<=y_{i}<=n$ ) shows that the $y_{i}$ -th ray exits from the $i$ -th hole. All rays are numbered from $1$ to $n$ .

输出格式

Output contains the only integer which is the number of rays in the largest group of rays all of which intersect each other.

输入输出样例

输入 #1
5
1 4 5 2 3
3 4 2 1 5
输出 #1
3
输入 #2
3
3 1 2
2 3 1
输出 #2
2
C++ 编辑器
输入
输出