P29333 [洛谷] [COCI2016-2017#1] Kralj
提高
题目描述

Problem Description

A war is about to break out between the Dwarf Kingdom and the Elf Kingdom! King Slavko of the Elves numbered his $n$ Elves as $1 \dots n$. King Mirko of the Dwarves arranged his $n$ Dwarves in a circle and numbered them clockwise starting from a certain Dwarf as $1 \dots n$.

Next, Mirko assigned a number $a_i$ to each Elf, indicating the number of the Dwarf they will duel with. However, due to his carelessness, different Elves might be assigned the same number.

To ensure fairness in the duels, both sides agreed on the following procedure:

  1. Slavko selects an Elf who has not yet been assigned a opponent, let's say with the number $i$.
  2. If the Dwarf numbered $a_i$ has not yet been assigned an opponent, he will be the opponent for this Elf. Otherwise, starting from the Dwarf numbered $a_i$, the first Dwarf in the clockwise direction who has not yet been assigned an opponent will be the opponent for this Elf.
  3. Repeat the above steps until all Dwarves and Elves have been assigned opponents.

Slavko has collected the strength values of all Dwarves and Elves. In the duels, the side with the higher strength value always wins. He wants to know how many Elves can win at most in the duels by strategically choosing the order in which Elves are selected.

Input Format

The first line contains an integer $n$.

The second line contains $n$ integers $a_i$.

The third line contains $n$ integers $p_i$, representing the strength values of the Dwarves numbered $i$.

The fourth line contains $n$ integers $v_i$, representing the strength values of the Elves numbered $i$.

Output Format

A single line containing an integer, representing the maximum number of Elves that can win in the duels.

Sample Input and Output

Sample Input #1

3
2 3 3
4 1 10
2 7 3

Sample Output #1

2

Sample Input #2

4
3 1 3 3
5 8 7 10
4 1 2 6

Sample Output #2

1

Sample Input #3

3
1 2 3
8 4 3
9 2 6

Sample Output #3

2

Notes/Hints

Sample 1 Explanation

Slavko selects Elves in the order $3, 2, 1$.

Thus, the opponents for Elves numbered $1, 2, 3$ are Dwarves numbered $2, 1, 3$ respectively.

Elves numbered $1, 2$ will win in the duels.

Data Size and Constraints

For $100\%$ of the data, $1 \le n \le 5 \times 10^5$, $1 \le a_i \le n$, $1 \le p_i, v_i \le 10^9$.

Notes

This problem is translated from COCI2016-2017 CONTEST #1 T5 Kralj.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2 3 3 4 1 10 2 7 3
样例输出
2