#P16657. [GKS 2018 #G] Combining Classes
[GKS 2018 #G] Combining Classes
Problem Description
Supervin is teaching classes, which are numbered from to . After giving his most recent exam, he noticed that in each of his classes, the test scores of his students form a sequence of consecutive integers. Therefore, Supervin can summarize the scores for the i-th class as two integers and . This means that the i-th class has students, and for each (), there is exactly one student with score .
Supervin would like to combine the scores from the students from all of his classes and sort the scores in non-increasing order. He has questions (numbered from to ) about this list; for the i-th question, he wants to know what the -th highest score is. (If is greater than the number of students, then the answer for the i-th question is .)
Can you help Supervin answer all of his questions? Since there may be many answers, instead of outputting all of them, output proof that you have answered them: the sum of for all , where is the answer to the i-th question.
Input Format
The first line of the input gives the number of test cases, T. T test cases follow. Each test case contains four lines. The first line contains two integers N and Q as described above. The next three lines each contain six integers in the following format, respectively:
These values are used to generate , , and as follows:
We define:
- $X_i = (A_1 \times X_{i - 1} + B_1 \times X_{i - 2} + C_1)$ modulo , for i = 3 to N.
- $Y_i = (A_2 \times Y_{i - 1} + B_2 \times Y_{i - 2} + C_2)$ modulo , for i = 3 to N.
- $Z_i = (A_3 \times Z_{i - 1} + B_3 \times Z_{i - 2} + C_3)$ modulo , for i = 3 to Q.
We also define:
- , for i = 1 to N.
- , for i = 1 to N.
- , for i = 1 to Q.
Output Format
For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the sum of for all , where is the answer to the i-th question.
2
5 1
3 1 4 1 5 9
2 7 1 8 2 9
4 8 15 16 23 42
7 1
2 3 4 5 6 31
1 3 4 5 5 17
2 2 1 3 2 100
Case #1: 7
Case #2: 28
2
5 5
3 1 4 1 5 9
2 7 1 8 2 9
4 8 15 16 23 42
1 2
0 0 0 0 0 1
0 0 0 0 0 1
0 1 0 0 0 2
Case #1: 39
Case #2: 1
Hint
In Sample Case #1, the generated arrays X, Y, Z are:
- .
- .
- .
Therefore,
- .
- .
- .
The students' scores for each of the classes are , , , , and . This means that the students' scores for all classes combined are $[3, 4, 2, 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 1, 2, 3, 7, 8, 9]$. If we sort them in non-increasing order, they are $[9, 8, 8, 8, 7, 7, 7, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 1]$. Therefore, the student with the 5th highest score has score 7. Thus, and the answer is .
Limits
.
.
, for all i.
, for all i.
, for all i.
.
.
.
.
.
.
, for all i.
Small dataset (Test set 1 - Visible)
.
Large dataset (Test set 2 - Hidden)
.