CF67D.Optical Experiment

普及+/提高

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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.

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.

王德教授对光线进行了一些实验。对于 nn 条光线,实验装置如下:

有一个长方体盒子,其相对的两个面上恰好各有 nn 个孔。所有光线均从第一个面的孔进入,并从另一面的孔射出。每个孔恰好允许一条光线进入或射出。这些孔位于同一条直线上。

王德教授正在向学生们演示该实验。他指出,存在某些情形,使得每条光线都与其他所有光线相交。一位好奇的学生向教授提问:“老师,存在一些光线组,其中组内每条光线都与该组内的其他所有光线相交。我们能否确定这类组中所含光线数的最大值?”

王德教授此时犯了难,鉴于您卓越的才智,他特地请您协助解决这个问题。

输入格式

The first line contains n (1 ≤ n ≤ 106), 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.

第一行包含一个整数 nn(1≤n≤1061 \leq n \leq 10^6),表示光线的数量。
第二行包含 nn 个互不相同的整数。其中第 ii 个整数 xix_i(1≤xi≤n1 \leq x_i \leq n)表示第 xix_i 条光线从第 ii 个孔进入。
类似地,第三行也包含 nn 个互不相同的整数。其中第 ii 个整数 yiy_i(1≤yi≤n1 \leq y_i \leq n)表示第 yiy_i 条光线从第 ii 个孔射出。
所有光线编号为 11 到 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.

对于第一个测试用例,图示如上。第一个测试用例的输出为 3,因为编号为 1、4 和 3 的射线两两相交,即:射线 1 被射线 4 和 3 所交;射线 3 被射线 4 和 1 所交;射线 4 被射线 1 和 3 所交。因此,该组中每条射线均与其他所有射线相交。不存在包含超过 3 条射线且满足上述约束条件的组。

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

首页