#P8868. [NOIP2022] 比赛
[NOIP2022] 比赛
Description
Xiao N and Xiao O will take part in the grand programming contest NOIP in November 2022, and Xiao P will serve as the judge. Xiao N and Xiao O each lead a team of people, and players in each team are numbered from to . Every player has a programming skill level. Specifically, in Xiao N's team, the player with index () has skill level ; in Xiao O's team, the player with index () has skill level . In particular, and each form a permutation of to .
Before each match, considering factors such as travel distance and players competing in consecutive matches, Xiao P chooses two parameters (), meaning that for this match all players whose indices are in from both teams will come to the venue to get ready. At the venue, Xiao N and Xiao O will pick parameters by rolling dice (), and only players with indices in are eligible to compete. To deliver the most exciting match to the audience, both teams will send the player with the maximum programming skill value whose index lies in . Suppose Xiao N sends a player with skill , and Xiao O sends a player with skill ; then the excitement of the match is .
There are matches in total in NOIP. For each match, the parameters are fixed, but have not yet been drawn. Xiao P wants to know, for each match, the sum of the excitement values over all possible choices of (). Since the answer can be very large, for each match you only need to output the result modulo .
Input Format
The first line contains two positive integers , denoting the test point id and the number of participants, respectively. If the input is a sample, it is guaranteed that .
The second line contains positive integers; the -th integer is , the programming skill level of the player with index in Xiao N's team.
The third line contains positive integers; the -th integer is , the programming skill level of the player with index in Xiao O's team.
The fourth line contains a positive integer , the number of matches.
Each of the next lines contains two positive integers , the parameters for the -th match.
Output Format
Output lines. The -th line should contain a non-negative integer, which is the sum of the excitement values over all possible matches for the -th query, modulo .
0 2
2 1
1 2
1
1 2
8
见附件下的 match/match2.in。
见附件下的 match/match2.ans。
见附件下的 match/match3.in。
见附件下的 match/match3.ans。
Hint
【Sample 1 Explanation】
When , Xiao N will send player , and Xiao O will send player , so the excitement is .
When , Xiao N will send player , and Xiao O will send player , so the excitement is .
When , Xiao N will send player , and Xiao O will send player , so the excitement is .
【Sample 2】
This sample satisfies the constraints of test points .
【Sample 3】
This sample satisfies the constraints of test points .
【Constraints】
For all testdata, it is guaranteed that: , , , and and each form a permutation of to .
::cute-table{tuack} | Test points | | | Special property A | Special property B | | :----------: | :----------: | :----------: | :----------: | :----------: | | | | | Yes | Yes | | | | | ^ | ^ | | | | | ^ | ^ | | | | ^ | ^ | ^ | | | | ^ | No | No | | | | ^ | ^ | ^ | | | | | Yes | Yes | | | | | ^ | ^ | | | | | ^ | No | | | | | ^ | ^ | | | | | No | ^ | | | | | ^ | ^ |
Special property A: It is guaranteed that is a uniformly random permutation of .
Special property B: It is guaranteed that is a uniformly random permutation of .
Translated by ChatGPT 5
京公网安备 11011102002149号