#P10888. 【MX-S3-T4】「FeOI Round 1」醒餞の鳥 (feat. Feryquitous)

【MX-S3-T4】「FeOI Round 1」醒餞の鳥 (feat. Feryquitous)

Background

Original link: https://oier.team/problems/S3D


Problem Description

There are nn students (numbered 1n1 \sim n) taking an exam with mm subjects (numbered 1m1 \sim m). You are given that student ii's score in subject jj is ai,ja_{i, j}

Now you want to rank these students. Since it is hard to compare the ability of two students whose scores do not form a partial order, you plan to set mm real numbers p1mp_{1 \sim m} (required to satisfy i=1mpi=1\sum_{i = 1}^m p_i = 1 and pi0p_i \ge 0) as weights. Define student ii's weighted total score as j=1mai,j×pj\sum_{j = 1}^m a_{i, j} \times p_j. Then students are ranked in descending order of weighted total score, and students with equal weighted total score share the same rank。

Now all mm subject teachers have made requests to you. The teacher of subject kk wants your chosen pp to satisfy:

  • In the ranking result obtained by this pp, there does not exist a pair of students (x,y)(x, y) (xyx \ne y) such that xx ranks higher (ties do not count), but ax,k<ay,ka_{x, k} < a_{y, k}

Because you want to distribute the weights as freely as possible, for each kk (1km1 \le k \le m), you need to compute separately:

  • What is the minimum value of pkp_k such that no matter how the other pi\boldsymbol{p_i} are distributed, the teacher of subject kk's requirement is always satisfied? Output the result modulo 998244353998244353

Input Format

This problem contains multiple test cases within a single input file.

The first line contains an integer TT denoting the number of test cases。

For each test case, the format is:

The first line contains two integers n,mn, m

Lines 22 to n+1n + 1 each contain mm integers. The integer in row i+1i + 1, column jj denotes ai,ja_{i, j}

Output Format

For each test case, output mm lines, each containing a non-negative integer. The ii-th line represents the result when k=ik = i, i.e., the minimum value of pkp_k modulo 998244353998244353

That is, suppose the answer in lowest terms is ab\frac{a}{b}, where aa and bb are coprime. Output an integer xx such that bxa(mod998244353)bx \equiv a \pmod{998244353} and 0x<9982443530 \le x < 998244353。It can be proven that such an integer xx is unique。

4
4 4
4 2 4 3
1 3 1 2
1 2 4 2
4 2 4 3
10 2
1 2
4 0
3 1
2 4
0 5
2 3
3 2
1 1
2 2
4 4
4 4
0 0 0 0
0 0 0 0
1 0 1 0
0 0 0 0
2 10
92603107 17358677 20869254 22085089 68529385 51524980 47064864 17692636 31121387 37022044
25517267 69562538 61254114 54886162 15087981 27505611 76082026 59892091 54661294 59475460
748683265
249561089
748683265
499122177
399297742
399297742
0
0
0
0
892513752
105730602
366911811
374997189
954012663
897963459
891479524
220357565
706471693
519276178

Hint

[Sample Explanation]

For the first test case, the answers before taking modulo are 14,34,14,12\frac{1}{4}, \frac{3}{4}, \frac{1}{4}, \frac{1}{2} respectively。

For the second test case, the answers before taking modulo are 45,45\frac{4}{5}, \frac{4}{5} respectively。

For the third test case, the answers before taking modulo are 0,0,0,00, 0, 0, 0 respectively。

For the query with k=2k = 2 in the first test case, suppose p=[0.1,0.75,0.1,0.05]p = [0.1, 0.75, 0.1, 0.05]:

  • Student 11's weighted total score is $4 \times 0.1 + 2 \times 0.75 + 4 \times 0.1 + 3 \times 0.05 = 2.45$;
  • Student 22's weighted total score is $1 \times 0.1 + 3 \times 0.75 + 1 \times 0.1 + 2 \times 0.05 = 2.55$;
  • Student 33's weighted total score is $1 \times 0.1 + 2 \times 0.75 + 4 \times 0.1 + 2 \times 0.05 = 2.1$;
  • Student 44's weighted total score is $4 \times 0.1 + 2 \times 0.75 + 4 \times 0.1 + 3 \times 0.05 = 2.45$;

Then you rank the students (by descending weighted total score) as [2,4,1,3][2, 4, 1, 3] (of course it can also be [2,1,4,3][2, 1, 4, 3]). Also, $a_{2, 2} = 3, a_{4, 2} = 2, a_{1, 2} = 2, a_{3, 2} = 2$, and there is no case where a lower-ranked student has a higher score in subject 22

It can be proven that when p20.75p_2 \ge 0.75, no matter how the other pip_i are distributed, the requirement can be satisfied; while when p2<0.75p_2 < 0.75, there must exist a distribution of the other pip_i that makes the requirement impossible to satisfy。

[Constraints]

This problem uses bundled tests.

Let nm\sum nm be the sum of all nmnm over all test cases within a single input file。

For 100%100\% of the testdata, 1T5×1041 \le T \le 5 \times 10^4, 2n,m105 2 \le n, m \le 10^5, nm2×105 \sum nm \le 2 \times 10^5, 0ai,j108 0 \le a_{i, j} \leq 10^8

Subtask ID nn mm nm\sum nm Special Property Score
11 10\leq 10 100\leq 100 None 55
22 100\leq 100 104\leq 10^4 1010
33 5×103\leq 5 \times 10^3 1515
44 100\leq 100 105\le 10^5 2×105\le 2 \times 10^5 2020
55 105\le 10^5 100\leq 100 1010
66 105\le 10^5 ai,j{0,1}a_{i, j} \in \{0, 1\} 2020
77 None

Translated by ChatGPT 5