#P4477. [BJWC2018] 基础匹配算法练习题

[BJWC2018] 基础匹配算法练习题

Description

Xiao S recently learned the Hungarian algorithm for bipartite matching.

Now the X part of a bipartite graph has NN numbers AiA_i, and the Y part has KK numbers CiC_i.

If Ai+CjZA_i + C_j \le Z, then there is an edge between AiA_i and CjC_j. Find the maximum matching size of the bipartite graph (X,E,Y)(X, E, Y).

Xiao S is a beginner, so she wants to do more practice to consolidate her knowledge. She found a positive integer array BB of length MM. Each time, she picks a continuous subarray [Li,Ri][L_i, R_i] from BB, takes all numbers in [Li,Ri][L_i, R_i] as the KK numbers CiC_i on the Y part of the bipartite graph, and then recomputes the maximum matching size.

Xiao S plans to do QQ practice sessions, but she is not sure whether each computed answer is correct. Can you help her?

Input Format

The first line contains three positive integers N,M,ZN, M, Z.

The second line contains NN positive integers, where the ii-th integer is AiA_i.

The third line contains MM positive integers, where the ii-th integer is BiB_i.

The fourth line contains an integer QQ denoting the number of queries.

Each of the next QQ lines contains two positive integers; on the ii-th line, the two integers are Li,RiL_i, R_i.

Output Format

For each practice session, output the answer for that session.

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

Hint

Testdata ID NN MM QQ
141 \sim 4 50\le 50
5105 \sim 10 2501\le 2501
111411 \sim 14 152501\le 152501 45678\le 45678
15,1615 ,16 50\le 50 52501\le 52501
172017 \sim 20 52501\le 52501

For 100%100\% of the testdata, 1Ai,Bi,Z1091 \le A_i, B_i, Z \le 10^9, 1LiRiM1 \le L_i \le R_i \le M.

The testdata is graded.

Translated by ChatGPT 5