CF67D Optical Experiment

题目描述

如图所示,有 $n$ 条光线从矩形上边的 $n$ 个洞射入矩形区域后从下边的 $n$ 个洞射出。 已知从第 $i$ 个洞射入的光线编号为 $x_i$,从第 $i$ 个洞射出的光线编号为 $y_i$,要求从这 $n$ 条光线中选出最多数量的光线,使得这些光线中任意两条都会在矩形区域内相交。

输入格式

第一行一整数 $n$ $(1 \leq n \leq 10^6)$ 表示光线数量,之后 $n$ 个整数 $x_i$ 表示从第 $i$ 个洞射入的光线编号,最后 $n$ 个整数 $y_i$ 表示从第 $i$ 个洞射出的光线编号。

输出格式

输出所选光线数量最大值。

说明/提示

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.