#P7169. [eJOI 2020] Exam (Day1)

    ID: 8008 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2020树状数组eJOI(欧洲)

[eJOI 2020] Exam (Day1)

Problem Description

Given a sequence AiA_i of length NN, you can perform the following operation any number of times:

  • Choose an interval of length at least 22, such that all numbers in this interval are equal to the maximum value in this interval.

You need to use these operations to make Ai=BiA_i = B_i. Find the maximum number of positions that can be made to satisfy the requirement.

Input Format

The first line contains an integer NN, representing the length of the sequence.
The second line contains NN integers, representing the sequence AiA_i.
The third line contains NN integers, representing the sequence BiB_i.

Output Format

Output one integer on a single line, representing the answer.

3
1 2 3
2 2 2
2
4
10 1 9 1
10 9 10 9
3

Hint

Sample 1 Explanation

You can choose to perform the operation on the interval [1,2][1,2]. At most 22 numbers can satisfy the requirement.

Sample 2 Explanation

Either A2A_2 or A3A_3 can satisfy the requirement, but they cannot satisfy the requirement at the same time.

Constraints

This problem uses bundled testdata.

  • Subtask 1 (14 pts): N10N \le 10.
  • Subtask 2 (12 pts): N105N \le 10^5, all BiB_i are equal.
  • Subtask 3 (13 pts): N5000N \le 5000, AiA_i is a strictly increasing sequence.
  • Subtask 4 (23 pts): N105N \le 10^5, all AiA_i are pairwise distinct.
  • Subtask 5 (16 pts): N200N \le 200.
  • Subtask 6 (22 pts): N5000N \le 5000.

For 100%100\% of the testdata:

  • 2N2 \le N.
  • 1Ai1091 \le A_i \le 10^9.
  • 1Bi1091 \le B_i \le 10^9.

Note

Translated from eJOI 2020 Day1 C Exam

Translated by ChatGPT 5