CF1792D.Fixed Prefix Permutations
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n permutations a1,a2,…,an, each of length m. Recall that a permutation of length m is a sequence of m distinct integers from 1 to m.
Let the beauty of a permutation p1,p2,…,pm be the largest k such that p1=1,p2=2,…,pk=k. If p1=1, then the beauty is 0.
The product of two permutations p⋅q is a permutation r such that rj=qpj.
For each i from 1 to n, print the largest beauty of a permutation ai⋅aj over all j from 1 to n (possibly, i=j).
给你 n 个长度为 m 的排列 a1,a2,…,an。回忆一下,一个长度为 m 的排列是由 1 到 m 的 m 个互不相同的整数组成的序列。
定义一个排列 p1,p2,…,pm 的**优美值(beauty)**为最大的 k,使得 p1=1,p2=2,…,pk=k;若 p1=1,则其优美值为 0。
两个排列 p 与 q 的乘积 p⋅q 是一个排列 r,满足 rj=qpj。
对每个从 1 到 n 的 i,输出在所有 j(1≤j≤n,允许 i=j)中,排列 ai⋅aj 的最大优美值。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of testcases.
The first line of each testcase contains two integers n and m (1≤n≤5⋅104; 1≤m≤10) — the number of permutations and the length of each permutation.
The i-th of the next n lines contains a permutation ai — m distinct integers from 1 to m.
The sum of n doesn't exceed 5⋅104 over all testcases.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 m(1≤n≤5⋅104;1≤m≤10)—— 排列的个数以及每个排列的长度。
接下来 n 行中的第 i 行包含一个排列 ai —— 由 1 到 m 中互不相同的 m 个整数组成。
所有测试用例中 n 的总和不超过 5⋅104。
输出格式
For each testcase, print n integers. The i-th value should be equal to the largest beauty of a permutation ai⋅aj over all j (1≤j≤n).
对于每个测试用例,输出 n 个整数。其中第 i 个值应等于所有 j(1≤j≤n)对应的排列 ai⋅aj 的最大美观度。
输入输出样例
输入#1
3 3 4 2 4 1 3 1 2 4 3 2 1 3 4 2 2 1 2 2 1 8 10 3 4 9 6 10 2 7 8 1 5 3 9 1 8 5 7 4 10 2 6 3 10 1 7 5 9 6 4 2 8 1 2 3 4 8 6 10 7 9 5 1 2 3 4 10 6 8 5 7 9 9 6 1 2 10 4 7 8 3 5 7 9 3 2 5 6 4 8 1 10 9 4 3 7 5 6 1 10 8 2
输出#1
1 4 4 2 2 10 8 1 6 8 10 1 7
输入解题思路,AI测评打分。不知道怎么写?