#P5338. [TJOI2019] 甲苯先生的滚榜

[TJOI2019] 甲苯先生的滚榜

Problem Description

Mr. Toluene is building an Online Judge. He noticed that people participating in contests care a lot about their rank (obviously).

In an ACM-style contest, if the numbers of solved problems are different, the person who solved more problems ranks higher.
If the numbers of solved problems are the same, the person with less penalty time ranks higher.

Mr. Toluene wants everyone to help design a program: after each time someone gets an accepted solution, tell him how many people are ranked ahead of that person.
(This does not include contestants who have exactly the same number of solved problems and the same penalty time.)

Input Format

The first line contains an integer TT, the number of test cases.

For each test case, input three integers m,n,seedm, n, \text{seed}.
mm is the total number of contestants (numbered 1m1 \sim m), nn means there are nn AC events in total (assume AC events are already deduplicated, i.e., there is no submission of the same problem by the same person).
seed\text{seed} is the seed used to generate the data.

Then you must use the following function to generate the data:

typedef unsigned int ui ;
ui randNum( ui& seed , ui last , const ui m){ 
    seed = seed * 17 + last ; return seed % m + 1; 
}

(last\texttt{last} is the previous output value. When there has been no output yet, last=7\texttt{last} = 7. For multiple test cases, last\texttt{last} does not need to be reset.)
Each time, generate two values Ria,Rib\texttt{Ria}, \texttt{Rib}, meaning that contestant Ria\texttt{Ria} gets an AC for one problem, and the added penalty time is Rib\texttt{Rib}.
(That is, the solved count of Ria\texttt{Ria} becomes +1+1, and the penalty time becomes +Rib+\texttt{Rib}.)

Generate a total of nn pairs of data, meaning there are nn submissions in total.

For all testdata, it is guaranteed that the total sum of penalty times does not exceed 1.5×1061.5\times 10^6.

Output Format

For each submission, output one line with an integer: after contestant Ria\texttt{Ria} gets an AC, how many contestants have a better result than Ria\texttt{Ria}.

1
7 3 1

0
1
0

Hint

Test Point # 1, 2 3, 4 5 6, 7, 8 9, 10
TT 10\le10 5\le5 15\le15 5\le5
mm 1000\le1000 10000\le10000 105\le10^5 104\le10^4 105\le10^5
nn 106\le10^6

Translated by ChatGPT 5