Yet Another LIS Problem Codechef Solution | APRIL CHALLENGE

Codechef
Share:

Yet Another LIS Problem Codechef Solution

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 33 integers MM, PP, and NN.

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

Consider all distinct arrays AA of length NN such that 1≤Ai≤M1≤Ai≤M for all (1≤i≤N)(1≤i≤N). Calculate the sum of g(A)g(A) over all such MNMN arrays. Since the answer can be huge, print it modulo 754974721754974721.

Each test case has QQ queries. For all QQ queries, MM and PP remain the same, only NN varies.

Input Format

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

Output Format

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

Constraints

  • 1≤T≤41≤T≤4
  • 1≤M≤141≤M≤14
  • 1≤P≤1061≤P≤106
  • 1≤N≤1091≤N≤109
  • 1≤Q≤501≤Q≤50

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 11: In the first query there are 11=111=1 distinct arrays. The array is : [1][1].

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

Sum of g(A)g(A) is 11.

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

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

Sum of g(A)g(A) is 11.

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

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

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

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

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

Yet Another LIS Problem Codechef  SOLUTION

Download Code
login to google play console, youtube video search by image, how to add a google account, which are the google apps, what is the google app, how to add a new google account, all the google apps, which service is the part of google, adsetting google, google data studio, google DNS, GCP console, bigquery, google studio, google api console, google app engine, anthos, google apis, google public DNS, google audio, google launcher, gcloud console, google compute engine, google webmaster console, google logged-in devices, gdrive unlimited,google console tools,google studio login,my google voice,hey google service,find similar images google, my google forms, www google com bd search, search using images in google,google image search scan,google sea console,website console google, google sound, gdrive storage for students, google site console, google console login, webmaster console, searc h console, google server down, google backup login, photo finder google, google products and services, google console tool, google image check, google cloud search is used for, google dashboard studio, google voice and audio activity,gcp dashboards, google services down, google go app, google dns down, google image identifier,check picture on google,google new launcher,google image finder online,image check google google google go, image finder on google, finding images on google, photo find google, find a picture in google, find the photo on google, picture find google, image find on google, find with photo google, image finder google online, google find with image, photo finder in google, google find image search, search using image in google, search on google with image, google server down today, google server down news

Read More Post Here

Leave a Comment

Your email address will not be published. Required fields are marked *

x