#P10058. [CF261D]Maxim and Increasing Subsequence

[CF261D]Maxim and Increasing Subsequence

Maxim and Increasing Subsequence

题面翻译

给你一个长度为nnBB数组,AA表示BB数组复制tt遍后首尾相连后的数组,求AA的最长上升子序列 有kk组询问 maxbmaxb表示BB数组中最大的数

题目描述

Maxim loves sequences, especially those that strictly increase. He is wondering, what is the length of the longest increasing subsequence of the given sequence a a ?

Sequence a a is given as follows:

  • the length of the sequence equals n×t n×t ;
  • (1<=i<=n×t) (1<=i<=n×t) , where operation means taking the remainder after dividing number x x by number y y .

Sequence s1,s2,...,sr s_{1},s_{2},...,s_{r} of length r r is a subsequence of sequence a1,a2,...,an a_{1},a_{2},...,a_{n} , if there is such increasing sequence of indexes i1,i2,...,ir i_{1},i_{2},...,i_{r} (1<=i_{1}&lt;i_{2}&lt;...\ &lt;i_{r}<=n) , that aij=sj a_{ij}=s_{j} . In other words, the subsequence can be obtained from the sequence by crossing out some elements.

Sequence s1,s2,...,sr s_{1},s_{2},...,s_{r} is increasing, if the following inequality holds: s_{1}&lt;s_{2}&lt;...&lt;s_{r} .

Maxim have k k variants of the sequence a a . Help Maxim to determine for each sequence the length of the longest increasing subsequence.

输入格式

The first line contains four integers k k , n n , maxb maxb and t t $ (1<=k<=10; 1<=n,maxb<=10^{5}; 1<=t<=10^{9}; n×maxb<=2·10^{7}) $ . Each of the next k k lines contain n n integers b1,b2,...,bn b_{1},b_{2},...,b_{n} (1<=bi<=maxb) (1<=b_{i}<=maxb) .

Note that for each variant of the sequence a a the values n n , maxb maxb and t t coincide, the only arrays b b s differ.

The numbers in the lines are separated by single spaces.

输出格式

Print k k integers — the answers for the variants of the sequence a a . Print the answers in the order the variants follow in the input.

样例 #1

样例输入 #1

3 3 5 2
3 2 1
1 2 3
2 3 1

样例输出 #1

2
3
3