GUPTA MECHANICAL

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

Tuesday 19 July 2022

[Solution] The Third Problem Codeforces Solution



C. The Third Problem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a permutation a1,a2,,an of integers from 0 to n1. Your task is to find how many permutations b1,b2,,bn are similar to permutation a.

Two permutations a and b of size n are considered similar if for all intervals [l,r] (1lrn), the following condition is satisfied:where the MEX of a collection of integers c1,c2,,ck is defined as the smallest non-negative integer x which does not occur in collection c. For example, MEX([1,2,3,4,5])=0, and MEX([0,1,2,4,5])=3

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

Since the total number of such permutations can be very large, you will have to print its remainder modulo 109+7.

In this problem, a permutation of size n is an array consisting of n distinct integers from 0 to n1 in arbitrary order. For example, [1,0,2,4,3] is a permutation, while [0,1,1] is not, since 1 appears twice in the array. [0,1,3] is also not a permutation, since n=3 and there is a 3 in the array.

Input

Each test contains multiple test cases. The first line of input contains one integer t (1t104) — the number of test cases. The following lines contain the descriptions of the test cases.

The first line of each test case contains a single integer n (1n105) — the size of permutation a.

The second line of each test case contains n distinct integers a1,a2,,an (0ai<n) — the elements of permutation a.

It is guaranteed that the sum of n across all test cases does not exceed 105.

Output

For each test case, print a single integer, the number of permutations similar to permutation a, taken modulo 109+7.

No comments:

Post a Comment