#P16064. [CSPro 32] 仓库规划

[CSPro 32] 仓库规划

Background

Luogu's testdata is only for community sharing and is not official testdata. Official judging link: https://www.cspro.org/.

Problem Description

There are nn warehouses on Xixi Aifu Island, numbered 1⋯n1 \cdots n in order. Each warehouse has an mm-dimensional vector as its location code, which is used to describe the logistics relationship between warehouses.

Specifically, each warehouse ii may have a parent warehouse jj such that, in every dimension, the corresponding element of warehouse jj's location code is strictly greater than that of warehouse ii. For example, a warehouse with code (1,1,1)(1, 1, 1) can be the parent of (0,0,0)(0, 0, 0), but it cannot be the parent of (0,1,0)(0, 1, 0). If multiple warehouses satisfy this condition, choose the one with the smallest index as the parent warehouse of warehouse ii. If no warehouse satisfies the condition, then warehouse ii is a logistics center and has no parent warehouse.

Given the location codes of nn warehouses, compute the index of the parent warehouse for each warehouse.

Input Format

Read from standard input.

There are n+1n + 1 lines in total.

The first line contains two positive integers nn and mm, representing the number of warehouses and the dimension of the location codes.

The next nn lines give the location codes of the nn warehouses in order. The ii-th line (1≤i≤n1 \le i \le n) contains mm integers, representing the location code of warehouse ii.

Output Format

Write to standard output.

There are nn lines in total.

The ii-th line (1≤i≤n1 \le i \le n) outputs one integer, the index of the parent warehouse of warehouse ii. If warehouse ii has no parent, output 00 on the ii-th line.

4 2
0 0
-1 -1
1 2
0 -1
3
1
0
3

Hint

Sample Explanation

For warehouse 22: (−1,−1)(-1, -1), both warehouse 11: (0,0)(0, 0) and warehouse 33: (1,2)(1, 2) satisfy the parent condition, so we choose warehouse 11 with the smaller index as its parent.

Subtasks

50%50\% of the testdata satisfies m=2m = 2.

All testdata satisfies 0<m≤100 < m \le 10, 0<n≤10000 < n \le 1000, and every element in the location codes is an integer with absolute value not greater than 10610^6.

Translated by ChatGPT 5