A1336 | [COCI-2016_2017-contest1]#3 Kralj
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Young ruler Mirko has declared himself king of dwarves. Upon hearing this, Slavko felt threatened and soon declared himself king of elves! As there cannot be more than one king in the land, they have decided to resolve the issue of power once and for all.
Slavko will, along with N strongest elves of the kingdom, labeled with numbers from 1 to N, go visit Mirko’s castle. In the castle hall, they will be greeted by N strongest dwarves sitting in a circle, labeled clockwise with numbers from 1 to N.
Mirko has, upon entering the castle, given a number Ai to each of Slavko's elves – the label of the dwarf it will fight against. Unfortunately, he didn't make sure that each elf should get a unique adversary, and soon a terrible fight broke out.
They have decided to solve the problem in the following way:
● Slavko will send his elves to the hall one by one, in the order he chooses. The next elf can enter the hall only after the one before him found a place to sit.
● The elf labeled k will first approach the dwarf labeled Ak . If there isn’t an elf sitting beside the dwarf, he will sit there. Otherwise, he will continue walking, from dwarf to dwarf, clockwise, until he finds an unclaimed dwarf.
Now the N resulting pairs of elves and dwarves compete in armwrestling, and the stronger one always wins.
Slavko is well prepared for this event. He has studied all the fighters and determined the strength of each one. Now he wants to send the elves to the hall in the order which, after they all sit down, will bring the most victories for him.
Help him and calculate the highest number of victories in duels that can be achieved by elves!
Slavko will, along with N strongest elves of the kingdom, labeled with numbers from 1 to N, go visit Mirko’s castle. In the castle hall, they will be greeted by N strongest dwarves sitting in a circle, labeled clockwise with numbers from 1 to N.
Mirko has, upon entering the castle, given a number Ai to each of Slavko's elves – the label of the dwarf it will fight against. Unfortunately, he didn't make sure that each elf should get a unique adversary, and soon a terrible fight broke out.
They have decided to solve the problem in the following way:
● Slavko will send his elves to the hall one by one, in the order he chooses. The next elf can enter the hall only after the one before him found a place to sit.
● The elf labeled k will first approach the dwarf labeled Ak . If there isn’t an elf sitting beside the dwarf, he will sit there. Otherwise, he will continue walking, from dwarf to dwarf, clockwise, until he finds an unclaimed dwarf.
Now the N resulting pairs of elves and dwarves compete in armwrestling, and the stronger one always wins.
Slavko is well prepared for this event. He has studied all the fighters and determined the strength of each one. Now he wants to send the elves to the hall in the order which, after they all sit down, will bring the most victories for him.
Help him and calculate the highest number of victories in duels that can be achieved by elves!
输入格式
The first line of input contains the integer N (1 ≤ N ≤ 5⋅105)
The second line of input contains N integers Ai(1 ≤ Ai ≤ N), the adversaries chosen by Mirko.
The third line of input contains N integers Pi (1 ≤ Pi ≤ 109), the dwarves’ strengths.
The fourth line of input contains N integers Vi (1 ≤ Vi ≤ 109), the elves’ strengths.
All strengths from the input will be mutually distinct.
The second line of input contains N integers Ai(1 ≤ Ai ≤ N), the adversaries chosen by Mirko.
The third line of input contains N integers Pi (1 ≤ Pi ≤ 109), the dwarves’ strengths.
The fourth line of input contains N integers Vi (1 ≤ Vi ≤ 109), the elves’ strengths.
All strengths from the input will be mutually distinct.
输出格式
The first and only line of input must contain the maximum number of victories that can be achieved by elves.
输入输出样例
输入 #1
3 2 3 3 4 1 10 2 7 3
输出 #1
2
输入 #2
4 3 1 3 3 5 8 7 10 4 1 2 6
输出 #2
1
输入 #3
3 1 2 3 8 4 3 9 2 6
输出 #3
2
In test cases worth 40% of total points, Mirko will choose the dwarf labeled with 1 (Ai
= 1 for each i from 1 to N) as an adversary in each elf duel.
Clarification of the first test case: Slavko can sort the elves in the following way: 3, 2, 1. This way, the elf number 3 will sit beside dwarf
number 3, elf 2 will have to move one seat clockwise and sit beside dwarf 1, and the elf number 2 will sit
beside the dwarf number 2. Elves 1 and 2 will win their duels, and elf 3 will lose.
= 1 for each i from 1 to N) as an adversary in each elf duel.
Clarification of the first test case: Slavko can sort the elves in the following way: 3, 2, 1. This way, the elf number 3 will sit beside dwarf
number 3, elf 2 will have to move one seat clockwise and sit beside dwarf 1, and the elf number 2 will sit
beside the dwarf number 2. Elves 1 and 2 will win their duels, and elf 3 will lose.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted