#P9786. [ROIR 2020] 机器人锦标赛 (Day1)

[ROIR 2020] 机器人锦标赛 (Day1)

Problem Description

Translated from ROIR 2020 Day1 T4. Олимпиада для роботов , translator alpha1022.

The jury has prepared tasks for the Robot High-Speed Boolean Function Computation Championship.

One task for the robots is a table with mm rows and nn columns, where each cell has an integer weight. Denote the weight in row ii and column jj by xi,jx_{i,j}.
For each column, the weights of all cells in that column form a permutation of 0m10 \ldots m-1. In other words, all weights in each column are pairwise distinct:
if iki \ne k, then for all jj we have xi,jxk,jx_{i,j} \ne x_{k,j}, and 0xi,j<m0 \le x_{i,j} < m.

For each column, the jury sets a threshold: a non-negative integer zjz_j in [0,m][0,m]. You need to compute the value of a Boolean function using the values of all logical expressions of the form xi,j<zjx_{i,j} < z_j as inputs. A logical expression has value 11 if and only if it is true, otherwise it is 00.

In the contest, participants need to compute values of mm Boolean functions, one for each row. Each Boolean function is defined by a Non-repeating Monotone Linear Program (NMLP).

Consider the NMLP for row ii.
It is a sequence of n1n-1 instructions numbered from 1n11 \ldots n-1. Instruction pp is given by three numbers: apa_p, bpb_p, oppop_p. The value of oppop_p has only two possibilities: 11 means AND, 22 means OR.
The parameters ap,bpa_p, b_p satisfy 1ap,bp<n+p1 \le a_p, b_p < n+p.

Consider an array val[12n1]val[1\ldots 2n-1] containing only 00 and 11. For 1jn1 \le j \le n, val[j]=[xi,j<zj]val[j] = [x_{i,j} < z_j], where [P][P] denotes the value of expression PP.
The value of val[n+p]val[n+p] is computed using instruction pp:

  • If opp=1op_p = 1, then val[n+p]=(val[ap] and val[bp])val[n+p] = (val[a_p]\ \texttt{and}\ val[b_p]).
  • If opp=2op_p = 2, then val[n+p]=(val[ap] or val[bp])val[n+p] = (val[a_p]\ \texttt{or}\ val[b_p]).

The program is non-repeating, meaning that for p=1n1p = 1\ldots n-1, all the 2n22n-2 values among ap,bpa_p, b_p are pairwise distinct.

The result of executing the program is val[2n1]val[2n-1].

The jury has already prepared all xi,jx_{i,j}, and you need to determine the thresholds for each column to complete the task setup.
The jury considers a task balanced if and only if among all mm rows, exactly ss rows have final Boolean function value 11, and the remaining msm-s rows have value 00.
Your task is to find suitable thresholds for the jury.

For this problem, it can be proven that there exists at least one choice of thresholds satisfying the above condition.

Input Format

The first line contains three integers n,m,sn, m, s.
The next m(n1)m(n-1) lines describe the operations. Line i(n1)+pi \cdot (n-1) + p (1pn11 \le p \le n-1) contains three integers ap,bp,oppa_p, b_p, op_p, representing the pp-th operation of row ii.
The next mm lines each contain nn integers, describing all xi,jx_{i,j}.

Output Format

Output nn integers z1,z2,,znz_1, z_2, \ldots, z_n (0zjm0 \le z_j \le m).
If there are multiple solutions, output any one.

4 3 2
1 2 1
3 4 1
5 6 2
1 2 2
3 5 1
4 6 2
1 4 1
2 3 1
5 6 2
0 1 2 2
2 2 1 0
1 0 0 1
0 1 2 3

Hint

Sample Explanation

In this sample there are 33 rows. You need to make exactly two rows have function value 11, and the other row have function value 00.

Let us see what the valval array looks like for the first row. The first four values are computed from the cell weights and the thresholds:

  • val[1]=[x1,1<z1]=[0<0]=0val[1] = [x_{1,1} < z_1] = [0 < 0] = 0.
  • val[2]=[x1,2<z2]=[1<1]=0val[2] = [x_{1,2} < z_2] = [1 < 1] = 0.
  • val[3]=[x1,3<z3]=[2<2]=0val[3] = [x_{1,3} < z_3] = [2 < 2] = 0.
  • val[4]=[x1,4<z4]=[2<3]=1val[4] = [x_{1,4} < z_4] = [2 < 3] = 1.

Next, execute the linear program for the first row:

  • $val[5] = (val[1]\ \texttt{and}\ val[2]) = (0\ \texttt{and}\ 0) = 0$.
  • $val[6] = (val[3]\ \texttt{and}\ val[4]) = (0\ \texttt{and}\ 1) = 0$.
  • $val[7] = (val[5]\ \texttt{or}\ val[6]) = (0\ \texttt{or}\ 0) = 0$.

Therefore, the function value of the first row is 00.
By the way, if we rewrite these expressions, we get:

$$[((x_{1,1} < z_1)\ \texttt{and}\ (x_{1,2} < z_2))\ \texttt{or}\ ((x_{1,3} < z_3)\ \texttt{and}\ (x_{1,4} < z_4))]$$

Similarly, the function values of the second and third rows are:

$$[(((x_{2,1} < z_1)\ \texttt{or}\ (x_{2,2} < z_2))\ \texttt{and}\ (x_{2,3} < z_3))\ \texttt{or}\ (x_{2,4} < z_4)]$$

and

$$[((x_{3,1} < z_1)\ \texttt{and}\ (x_{3,4} < z_4))\ \texttt{or}\ ((x_{3,2} < z_2)\ \texttt{and}\ (x_{3,3} < z_3))]$$

When we set z1=0,z2=1,z3=2,z4=3z_1 = 0, z_2 = 1, z_3 = 2, z_4 = 3, we get the following expressions:

Second row:

$$[(((2 < 0)\ \texttt{or}\ (2 < 1))\ \texttt{and}\ (1 < 2))\ \texttt{or}\ (0 < 3)] = 1$$

Third row:

$$[((1 < 0)\ \texttt{and}\ (1 < 3))\ \texttt{or}\ ((0 < 1)\ \texttt{and}\ (0 < 2))] = 1$$

Note that this is not the only solution. Other feasible solutions include z1=0,z2=0,z3=3,z4=3z_1 = 0, z_2 = 0, z_3 = 3, z_4 = 3.

Constraints

For 100%100\% of the testdata: 1n,m31051 \le n, m \le 3 \cdot 10^5, nm3105n \cdot m \le 3 \cdot 10^5, 0sm0 \le s \le m, 1ap,bpn+p1 \le a_p, b_p \le n+p, 0xi,j<m0 \le x_{i,j} < m.
The detailed limits are shown in the table below:

Subtask ID Limit Points
11 n2,m103n \le 2, m \le 10^3 1010
22 n2,m105n \le 2, m \le 10^5
33 n10,m2n \le 10, m \le 2
44 xi,j=i1x_{i,j} = i-1 55
55 opp=1op_p = 1
66 n100n \le 100 2020
77 The NMLP is the same for every row. 1010
88 - 3030

Translated by ChatGPT 5