#P8349. [SDOI/SXOI2022] 整数序列
[SDOI/SXOI2022] 整数序列
Problem Description
Little D learned to create problems when he was three years old.
Little D has a positive integer sequence and an integer sequence .
Little D has queries. In each query, are given, and a new sequence is constructed, where $c_i=\begin{cases}1 & a_i=x \\-1 & a_i=y \\ 0 & \text{else}\end{cases}$.
It is guaranteed that among the there is at least one and at least one . He wants you to find an interval such that , and is maximized, and the in the interval cannot all be . You need to output this maximum value.
Note: When the condition is true, , otherwise .
Input Format
The first line contains two integers .
The second line contains integers, where the -th integer denotes .
The third line contains integers, where the -th integer denotes .
The next lines each contain two integers , representing one query.
Output Format
For each query, output one line with one integer, representing the maximum value of .
5 3
1 2 3 1 2
-2 3 2 -1 2
1 2
1 3
2 3
2
1
5
见附加样例文件中的 ex_sequence2.in
见附加样例文件中的 ex_sequence2.out
Hint
Constraints
This problem has test points.
- For test points , it is guaranteed that .
- For test points , it is guaranteed that the number of distinct values in does not exceed .
- For test points , it is guaranteed that , , and .
- For test point , it is guaranteed that and .
- For test points , it is guaranteed that and .
- For test points , it is guaranteed that .
- For test points , it is guaranteed that .
For all test points, , , , , , . It is guaranteed that for each query, the always contain at least one and at least one .
Translated by ChatGPT 5