Sunday, April 24, 2022

Yet Another LIS Problem

 Nayra doesn't like stories of people receiving random arrays as birthday presents, but this time she received random arrays as presents for her own birthday! After struggling for a day trying to figure out what to do with the array, she asked Aryan for help. He gave her the following problem.

You are given 3 integers MP and N.

For an array A, let f(A) be defined as the length of the longest strictly increasing subsequence of A and let g(A)=(f(A))P.

Consider all distinct arrays A of length N such that 1AiM for all (1iN). Calculate the sum of g(A) over all such MN arrays. Since the answer can be huge, print it modulo 754974721.

Each test case has Q queries. For all Q queries, M and P remain the same, only N varies.

Input Format

  • First line will contain T, the number of test cases. Then the test cases follow.
  • First line of each test case contains three integers M,P, and Q.
  • Second line of each test case contains Q integers, values of N for each query.

Output Format

For each testcase, output in a single line containing Q space-separated integers, answers for each query modulo 754974721.

Constraints

  • 1T4
  • 1M14
  • 1P106
  • 1N109
  • 1Q50

Sample Input 1 

4
1 1 2
1 2
2 1 2
1 2
2 2 2
1 2
2 1000000 2
1 2

Sample Output 1 

1 1 
2 5 
2 7 
2 392816544 

Explanation

Test case 1: In the first query there are 11=1 distinct arrays. The array is : [1].

  • f([1])= LIS of [1]=1. Also, g([1])=(f([1]))1=11=1.

Sum of g(A) is 1.

In the second query there are 12=1 distinct arrays. The array is : [1,1].

  • f([1,1])= LIS of [1,1]=1. Also, g([1,1])=(f([1,1]))1=11=1.

Sum of g(A) is 1.

Test case 2: In the first query there are 21=2 distinct arrays. The arrays are : [1] and [2].

  • f([1])= LIS of [1]=1. Also, g([1])=(f([1]))1=11=1.
  • f([2])= LIS of [2]=1. Also, g([2])=(f([2]))1=11=1. Sum of g(A) is 1+1=2.

In the second query there are 22=4 distinct arrays. The arrays are : [1,1],[1,2],[2,1] and [2,2].

  • f([1,1])= LIS of [1,1]=1. Also, g([1,1])=(f([1,1]))1=11=1.
  • f([1,2])= LIS of [1,2]=2. Also, g([1,2])=(f([1,2]))1=21=2.
  • f([2,1])= LIS of [2,1]=1. Also, g([2,1])=(f([2,1]))1=11=1.
  • f([2,2])= LIS of [2,2]=1. Also, g([2,2])=(f([2,2]))1=11=1.

Sum of g(A) is 1+2+1+1=5.

No comments:

Post a Comment

मुझे दिल में बसाना आसान नहीं....

पता है Recently i realised की मुझे दिल में बसाना आसान नहीं है बात-बात पे चिढ़ जाती हूं मैं दिल लगा लूं एक बार तो फिर ज़िद पे अड़...