#P8991. [北大集训 2021] 出题高手

[北大集训 2021] 出题高手

Background

CTT2021 D3T2

Problem Description

Alice is an expert at setting problems.

Alice sets one problem every day. After nn days, she has set nn problems.

On day n+1n+1, Alice does not set a new problem. She plans to choose some problems from the previous nn problems to form a contest. For convenience, she decides that the chosen problems must come from a continuous time interval, meaning they must be exactly all problems from day ll to day rr (1lrn1 \le l \le r \le n).

Alice also gives each problem a rating. The rating of the ii-th problem is ai(1000ai1001)a_i(-1000 \le a_i \le 1001). A higher rating means the problem is more about IQ, while a lower rating means it is more about coding.

Alice wants the contest to have a distinctive style, i.e., overall leaning toward coding or overall leaning toward IQ. For a contest formed by all problems from day ll to day rr, its distinctiveness is defined as (lrai)2rl+1\Large \frac{(\sum_l^r a_i)^2}{r-l+1}. Alice wants to maximize this distinctiveness.

Now, for mm queries of the form qli,qriql_i, qr_i, you need to answer: if Alice is only allowed to choose problems from day qliql_i to day qriqr_i, what is the maximum possible distinctiveness of the contest she can form? You need to output this value as a fraction.

Since Alice is far too good at setting problems, you may assume that the rating of each problem is randomly generated.

Input Format

The first line contains a positive integer nn.

The second line contains nn integers a1ana_1 \dots a_n, representing Alice's rating for the problem set on day ii.

The third line contains a positive integer mm.

The next mm lines each contain two positive integers qli,qriql_i, qr_i, representing a query.

Output Format

Output mm lines. Each line contains two integers pi,qip_i, q_i with gcd(pi,qi)=1\gcd(p_i, q_i) = 1, indicating the answer is piqi\frac{p_i}{q_i}. If the answer is 00, then pi=0p_i = 0 and qi=1q_i = 1.

5
-962 -445 -613 -9 920
3
1 5
3 5
1 3

4080400 3
846400 1
4080400 3

Hint

Subtask n=n= m=m= Score
11 20002000 100000100000 55
22 100000100000 11 1515
33 500000500000 3030
44 100000100000 50005000 1515
55 300000300000 3535

For Subtasks 22 and 33, all queries satisfy qli=1ql_i = 1 and qri=nqr_i = n.

All aia_i satisfy 1000ai1001-1000 \le a_i \le 1001. Also, for each aia_i, the testdata is generated by independently choosing an integer uniformly at random from [1000,1001][-1000, 1001] each time.

Translated by ChatGPT 5