#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 nn people, and players in each team are numbered from 11 to nn. Every player has a programming skill level. Specifically, in Xiao N's team, the player with index ii (1in1 \leq i \leq n) has skill level aia _ i; in Xiao O's team, the player with index ii (1in1 \leq i \leq n) has skill level bib _ i. In particular, {ai}\{a _ i\} and {bi}\{b _ i\} each form a permutation of 11 to nn.

Before each match, considering factors such as travel distance and players competing in consecutive matches, Xiao P chooses two parameters l,rl, r (1lrn1 \leq l \leq r \leq n), meaning that for this match all players whose indices are in [l,r][l, r] from both teams will come to the venue to get ready. At the venue, Xiao N and Xiao O will pick parameters p,qp, q by rolling dice (lpqrl \leq p \leq q \leq r), and only players with indices in [p,q][p, q] 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 [p,q][p, q]. Suppose Xiao N sends a player with skill mam _ a, and Xiao O sends a player with skill mbm _ b; then the excitement of the match is ma×mbm _ a \times m _ b.

There are QQ matches in total in NOIP. For each match, the parameters l,rl, r are fixed, but p,qp, q have not yet been drawn. Xiao P wants to know, for each match, the sum of the excitement values over all possible choices of p,qp, q (lpqrl \leq p \leq q \leq r). Since the answer can be very large, for each match you only need to output the result modulo 2642 ^ {64}.

Input Format

The first line contains two positive integers T,nT, n, denoting the test point id and the number of participants, respectively. If the input is a sample, it is guaranteed that T=0T = 0.

The second line contains nn positive integers; the ii-th integer is aia _ i, the programming skill level of the player with index ii in Xiao N's team.

The third line contains nn positive integers; the ii-th integer is bib _ i, the programming skill level of the player with index ii in Xiao O's team.

The fourth line contains a positive integer QQ, the number of matches.

Each of the next QQ lines contains two positive integers li,ril _ i, r _ i, the parameters l,rl, r for the ii-th match.

Output Format

Output QQ lines. The ii-th line should contain a non-negative integer, which is the sum of the excitement values over all possible matches for the ii-th query, modulo 2642 ^ {64}.

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 p=1,q=2p = 1, q = 2, Xiao N will send player 11, and Xiao O will send player 22, so the excitement is 2×2=42 \times 2 = 4.

When p=1,q=1p = 1, q = 1, Xiao N will send player 11, and Xiao O will send player 11, so the excitement is 2×1=22 \times 1 = 2.

When p=2,q=2p = 2, q = 2, Xiao N will send player 22, and Xiao O will send player 22, so the excitement is 1×2=21 \times 2 = 2.

【Sample 2】

This sample satisfies the constraints of test points 121 \sim 2.

【Sample 3】

This sample satisfies the constraints of test points 353 \sim 5.

【Constraints】

For all testdata, it is guaranteed that: 1n,Q2.5×1051 \leq n, Q \leq 2.5 \times 10 ^ 5, 1lirin1 \leq l _ i \leq r _ i \leq n, 1ai,bin1 \leq a _ i, b _ i \leq n, and {ai}\{a _ i\} and {bi}\{b _ i\} each form a permutation of 11 to nn.

::cute-table{tuack} | Test points | nn | QQ | Special property A | Special property B | | :----------: | :----------: | :----------: | :----------: | :----------: | | 1,21, 2 | 30\leq 30 | 30\leq 30 | Yes | Yes | | 3,4,53, 4, 5 | 3,000\leq 3,000 | 3,000\leq 3,000 | ^ | ^ | | 6,76, 7 | 105\leq 10 ^ 5 | 5\leq 5 | ^ | ^ | | 8,98, 9 | 2.5×105\leq 2.5 \times 10 ^ 5 | ^ | ^ | ^ | | 10,1110, 11 | 105\leq 10 ^ 5 | ^ | No | No | | 12,1312, 13 | 2.5×105\leq 2.5 \times 10 ^ 5 | ^ | ^ | ^ | | 14,1514, 15 | 105\leq 10 ^ 5 | 105\leq 10 ^ 5 | Yes | Yes | | 16,1716, 17 | 2.5×105\leq 2.5 \times 10 ^ 5 | 2.5×105\leq 2.5 \times 10 ^ 5 | ^ | ^ | | 18,1918, 19 | 105\leq 10 ^ 5 | 105\leq 10 ^ 5 | ^ | No | | 20,2120, 21 | 2.5×105\leq 2.5 \times 10 ^ 5 | 2.5×105\leq 2.5 \times 10 ^ 5 | ^ | ^ | | 22,2322, 23 | 105\leq 10 ^ 5 | 105\leq 10 ^ 5 | No | ^ | | 24,2524, 25 | 2.5×105\leq 2.5 \times 10 ^ 5 | 2.5×105\leq 2.5 \times 10 ^ 5 | ^ | ^ |

Special property A: It is guaranteed that aa is a uniformly random permutation of 1n1 \sim n.

Special property B: It is guaranteed that bb is a uniformly random permutation of 1n1 \sim n.

Translated by ChatGPT 5