luogu#P5012. 水の数列
水の数列
Background
came up with a very fun game...
Problem Description
now gives you a sequence of length . You may choose a number , and then obtain a score. The larger the score, the better.
The score is computed as follows:
First, mark all numbers that are less than or equal to . Then, your score is the sum of the squares of the lengths of every consecutive marked segment.
thought this was too easy, the answer is obviously just the maximum value so he changed the score to be the original score divided by the number you chose.
still thought this was too easy, so he requires that the number of segments obtained by your chosen number must be within the range to .
still thought this was too easy, so he added queries.
still thought this was too easy, so he decided to enforce online queries.
Input Format
The first line contains two positive integers , .
The second line contains positive integers , representing the sequence given by .
In the next lines, each line contains four positive integers , , , . You need to obtain the actual and as follows:
l = (a * lastans + x - 1) % n + 1;
r = (b * lastans + y - 1) % n + 1;
if (l > r) swap(l, r);
Here, denotes the product of the maximum score (the original score) from the previous query and the that achieves this maximum score. In particular, for the first query we define .
Output Format
Output lines. Each line contains two positive integers, representing the maximum score (the original score) that can be obtained for this query and the that achieves this maximum score. In particular, if there is no solution, output "" (in this case, is ). If there are multiple solutions, output the one with the largest chosen number.
wants to know whether you are guessing, so you also need to tell him , , and for this query.
See the sample for details.
5 3
3 5 1 2 4
233 666 1 3
555 999 2 3
123 987 233 888
25 5
1 3 0
10 4
2 3 0
-1 -1
3 3 0
Hint
${\rm Subtask\ 1(30\ pts)}:\qquad 1 \leq N,T \leq 10^2$
${\rm Subtask\ 2(30\ pts)}:\qquad 1 \leq N,T \leq 10^3$
${\rm Subtask\ 3(40\ pts)}:\qquad 1 \leq N \leq 10^6 \qquad 1 \leq T \leq 10^3$
All other input numbers are within the range of .
Translated by ChatGPT 5