CF67D.Optical Experiment

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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

There is a rectangular box having exactly nn 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.

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 nn ( 1<=n<=1061<=n<=10^{6} ), the number of rays. The second line contains nn distinct integers. The ii -th integer xix_{i} ( 1<=xi<=n1<=x_{i}<=n ) shows that the xix_{i} -th ray enters from the ii -th hole. Similarly, third line contains nn distinct integers. The ii -th integer yiy_{i} ( 1<=yi<=n1<=y_{i}<=n ) shows that the yiy_{i} -th ray exits from the ii -th hole. All rays are numbered from 11 to nn .

输出格式

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
    

说明/提示

For the first test case, the figure is shown above. The output of the first test case is 3, since the rays number 1, 4 and 3 are the ones which are intersected by each other one i.e. 1 is intersected by 4 and 3, 3 is intersected by 4 and 1, and 4 is intersected by 1 and 3. Hence every ray in this group is intersected by each other one. There does not exist any group containing more than 3 rays satisfying the above-mentioned constraint.

首页