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.
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.
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.
输入格式
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
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted