GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday, 15 November 2022

[Solution] Yet Another Array Counting Problem Codeforces Solution



E. Yet Another Array Counting Problem
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

The position of the leftmost maximum on the segment [l;r] of array x=[x1,x2,,xn] is the smallest integer i such that lir and xi=max(xl,xl+1,,xr).

You are given an array a=[a1,a2,,an] of length n. Find the number of integer arrays b=[b1,b2,,bn] of length n that satisfy the following conditions:

  • 1bim for all 1in;
  • for all pairs of integers 1lrn, the position of the leftmost maximum on the segment [l;r] of the array b is equal to the position of the leftmost maximum on the segment [l;r] of the array a.

Since the answer might be very large, print its remainder modulo 109+7.

Input

Each test contains multiple test cases. The first line contains a single integer t (1t103) — the number of test cases.

The first line of each test case contains two integers n and m (2n,m2105nm106).

The second line of each test case contains n integers a1,a2,,an (1aim) — the array a.

It is guaranteed that the sum of nm over all test cases doesn't exceed 106.

Output

For each test case print one integer — the number of arrays b that satisfy the conditions from the statement, modulo 109+7.


Note

In the first test case, the following 8 arrays satisfy the conditions from the statement:

  • [1,2,1];
  • [1,2,2];
  • [1,3,1];
  • [1,3,2];
  • [1,3,3];
  • [2,3,1];
  • [2,3,2];
  • [2,3,3].

In the second test case, the following 5 arrays satisfy the conditions from the statement:

  • [1,1,1,1];
  • [2,1,1,1];
  • [2,2,1,1];
  • [2,2,2,1];
  • [2,2,2,2]

No comments:

Post a Comment