Knowee
Questions
Features
Study Tools

For a permutation ๐‘ƒP of size ๐‘N, and an integer ๐‘˜ย (1โ‰ค๐‘˜โ‰ค๐‘)kย (1โ‰คkโ‰คN), define ๐‘“(๐‘ƒ,๐‘˜)f(P,k) as โˆ‘๐‘–=1๐‘โˆ’๐‘˜+1maxโก(๐‘ƒ๐‘–,๐‘ƒ๐‘–+1,๐‘ƒ๐‘–+2,โ€ฆ,๐‘ƒ๐‘–+๐‘˜โˆ’1)i=1โˆ‘Nโˆ’k+1โ€‹ max(P iโ€‹ ,P i+1โ€‹ ,P i+2โ€‹ ,โ€ฆ,P i+kโˆ’1โ€‹ ), i.e. the sum of maximum elements in all ๐‘˜k - sized subarrays.Let ๐‘”(๐‘,๐‘˜)g(N,k) denote the number of permutations ๐‘ƒP of size ๐‘N which have the maximum value of ๐‘“(๐‘ƒ,๐‘˜)f(P,k).Given an integer ๐‘N, find the value of ๐‘”(๐‘,๐‘˜)g(N,k) for each 1โ‰ค๐‘˜โ‰ค๐‘1โ‰คkโ‰คN.Since the value can be huge, print it modulo 109+710 9 +7.Note that a permutation of size ๐‘N consists of all elements from 11 to ๐‘N exactly once.Input FormatThe first line of input will contain a single integer ๐‘‡T, denoting the number of test cases.Each test case consists of a single integer ๐‘N - the size of the permutation.Output FormatFor each test case, output on a new line, ๐‘N space-separated integers denoting the value of ๐‘”(๐‘,๐‘˜)g(N,k) for each 1โ‰ค๐‘˜โ‰ค๐‘1โ‰คkโ‰คN, modulo 109+710 9 +7.Constraints1โ‰ค๐‘‡โ‰ค5001โ‰คTโ‰ค5001โ‰ค๐‘โ‰ค3โ‹…1051โ‰คNโ‰ค3โ‹…10 5 The sum of ๐‘N over all test cases does not exceed 3โ‹…1053โ‹…10 5 .Sample 1:InputOutput312312 26 2 6Explanation:Test case 11: There is only one possible permutation of size 11. Thus, ๐‘“([1],1)=1f([1],1)=1 and ๐‘”(1,1)=1g(1,1)=1.Test case 22:๐‘”(2,1)=2g(2,1)=2 as there are two permutations with maximum ๐‘“(๐‘ƒ,1)f(P,1)๐‘“([1,2],1)=1+2=3f([1,2],1)=1+2=3๐‘“([2,1],1)=2+1=3f([2,1],1)=2+1=3๐‘”(2,2)=2g(2,2)=2 as there are two permutations with maximum ๐‘“(๐‘ƒ,2)f(P,2)๐‘“([1,2],2)=2f([1,2],2)=2๐‘“([2,1],2)=2f([2,1],2)=2Test case 33: For ๐‘˜=1k=1 and ๐‘˜=3k=3, all permutations have the same value of ๐‘“(๐‘ƒ,๐‘˜)f(P,k), thus the answer is 66. However, for ๐‘˜=2k=2, the optimal permutations are [2,3,1][2,3,1] and [1,3,2][1,3,2] only.

Question

For a permutation ๐‘ƒP of size ๐‘N, and an integer ๐‘˜ย (1โ‰ค๐‘˜โ‰ค๐‘)kย (1โ‰คkโ‰คN), define ๐‘“(๐‘ƒ,๐‘˜)f(P,k) as โˆ‘๐‘–=1๐‘โˆ’๐‘˜+1maxโก(๐‘ƒ๐‘–,๐‘ƒ๐‘–+1,๐‘ƒ๐‘–+2,โ€ฆ,๐‘ƒ๐‘–+๐‘˜โˆ’1)i=1โˆ‘Nโˆ’k+1โ€‹ max(P iโ€‹ ,P i+1โ€‹ ,P i+2โ€‹ ,โ€ฆ,P i+kโˆ’1โ€‹ ), i.e. the sum of maximum elements in all ๐‘˜k - sized subarrays.Let ๐‘”(๐‘,๐‘˜)g(N,k) denote the number of permutations ๐‘ƒP of size ๐‘N which have the maximum value of ๐‘“(๐‘ƒ,๐‘˜)f(P,k).Given an integer ๐‘N, find the value of ๐‘”(๐‘,๐‘˜)g(N,k) for each 1โ‰ค๐‘˜โ‰ค๐‘1โ‰คkโ‰คN.Since the value can be huge, print it modulo 109+710 9 +7.Note that a permutation of size ๐‘N consists of all elements from 11 to ๐‘N exactly once.Input FormatThe first line of input will contain a single integer ๐‘‡T, denoting the number of test cases.Each test case consists of a single integer ๐‘N - the size of the permutation.Output FormatFor each test case, output on a new line, ๐‘N space-separated integers denoting the value of ๐‘”(๐‘,๐‘˜)g(N,k) for each 1โ‰ค๐‘˜โ‰ค๐‘1โ‰คkโ‰คN, modulo 109+710 9 +7.Constraints1โ‰ค๐‘‡โ‰ค5001โ‰คTโ‰ค5001โ‰ค๐‘โ‰ค3โ‹…1051โ‰คNโ‰ค3โ‹…10 5 The sum of ๐‘N over all test cases does not exceed 3โ‹…1053โ‹…10 5 .Sample 1:InputOutput312312 26 2 6Explanation:Test case 11: There is only one possible permutation of size 11. Thus, ๐‘“([1],1)=1f([1],1)=1 and ๐‘”(1,1)=1g(1,1)=1.Test case 22:๐‘”(2,1)=2g(2,1)=2 as there are two permutations with maximum ๐‘“(๐‘ƒ,1)f(P,1)๐‘“([1,2],1)=1+2=3f([1,2],1)=1+2=3๐‘“([2,1],1)=2+1=3f([2,1],1)=2+1=3๐‘”(2,2)=2g(2,2)=2 as there are two permutations with maximum ๐‘“(๐‘ƒ,2)f(P,2)๐‘“([1,2],2)=2f([1,2],2)=2๐‘“([2,1],2)=2f([2,1],2)=2Test case 33: For ๐‘˜=1k=1 and ๐‘˜=3k=3, all permutations have the same value of ๐‘“(๐‘ƒ,๐‘˜)f(P,k), thus the answer is 66. However, for ๐‘˜=2k=2, the optimal permutations are [2,3,1][2,3,1] and [1,3,2][1,3,2] only.

...expand
๐Ÿง Not the exact question you are looking for?Go ask a question

Solution

Para resolver este problema, sigamos los siguientes pasos:

  1. Entender el problema:

    • Necesitamos encontrar el nรบmero de permutaciones de tamaรฑo N N que tienen el valor mรกximo de f(P,k) f(P, k) para cada k k en el rango de 1 a N N .
    • f(P,k) f(P, k) se define como la suma de los mรกximos elementos en todos los subarreglos de tamaรฑo k k de la permutaciรณn P P .
  2. Observaciones:

    • Para k=1 k = 1 , f(P,1) f(P, 1) es simplemente la suma de todos los elementos de la permutaciรณn, que siempre es N(N+1)2 \frac{N(N+1)}{2} .
    • Para k=N k = N , f(P,N) f(P, N) es simplemente el mรกximo elemento de la permutaciรณn, que siempre es N N .
    • Para otros valores de k k , necesitamos considerar cรณmo se distribuyen los mรกximos en los subarreglos.
  3. Estrategia:

    • Para cada k k , necesitamos encontrar las permutaciones que maximiz

This problem has been solved

Similar Questions

Maximum Distance PermutationsDefine the distance between 22 permutationsโ€ โ€  ๐ดA and ๐ตB, each of length ๐‘N, as the minimum value of โˆฃ๐ด๐‘–โˆ’๐ต๐‘–โˆฃโ€กโˆฃA iโ€‹ โˆ’B iโ€‹ โˆฃ โ€ก for 1โ‰ค๐‘–โ‰ค๐‘1โ‰คiโ‰คN.Find a pair of permutations of length ๐‘N which have the maximum possible distance among all pairs of permutations of length ๐‘N.โ€ โ€  A permutation of length ๐‘N is an array of ๐‘N distinct elements which are all in the range [1,๐‘][1,N]. For example, [2,3,1,4][2,3,1,4] is a permutation of length 44 whereas [2,4,3][2,4,3] and [1,1,2][1,1,2] are not.โ€กโ€ก โˆฃ๐‘‹โˆฃโˆฃXโˆฃ denotes the absolute value of ๐‘‹X. For example, โˆฃโˆ’5โˆฃ=โˆฃ5โˆฃ=5โˆฃโˆ’5โˆฃ=โˆฃ5โˆฃ=5.Input FormatThe first line of input will contain a single integer ๐‘‡T, denoting the number of test cases.Each test case consists of a single integer ๐‘N - the length of the permutations.Output FormatFor each test case, output 22 lines.The first line containing ๐‘N space-separated integers - ๐ด1,๐ด2,๐ด3,โ€ฆ,๐ด๐‘A 1โ€‹ ,A 2โ€‹ ,A 3โ€‹ ,โ€ฆ,A Nโ€‹ , denoting the permutation ๐ดA.The second line containing ๐‘N space-separated integers - ๐ต1,๐ต2,๐ต3,โ€ฆ,๐ต๐‘B 1โ€‹ ,B 2โ€‹ ,B 3โ€‹ ,โ€ฆ,B Nโ€‹ , denoting the permutation ๐ตB.The permutations ๐ดA and ๐ตB must have the maximum distance possible. If multiple answers are possible, all will be accepted.Constraints1โ‰ค๐‘‡โ‰ค1001โ‰คTโ‰ค1001โ‰ค๐‘โ‰ค1001โ‰คNโ‰ค100Sample 1:InputOutput3123111 22 11 2 33 1 2Explanation:Test case 1 : There is only one possible permutation of length ๐‘N, and thus only one possible pair, which has distance 00.Test case 2 : The permutations [1,2][1,2] and [2,1][2,1] have a distance of 11. This can be shown to be the maximum possible distance.

Initially, we had one array, which was a permutation of size n๐‘› (an array of size n๐‘› where each integer from 11 to n๐‘› appears exactly once).We performed q๐‘ž operations. During the i๐‘–-th operation, we did the following:choose any array we have with at least 22 elements;split it into two non-empty arrays (prefix and suffix);write two integers li๐‘™๐‘– and ri๐‘Ÿ๐‘–, where li๐‘™๐‘– is the maximum element in the left part which we get after the split, and ri๐‘Ÿ๐‘– is the maximum element in the right part;remove the array we've chosen from the pool of arrays we can use, and add the two resulting parts into the pool.For example, suppose the initial array was [6,3,4,1,2,5][6,3,4,1,2,5], and we performed the following operations:choose the array [6,3,4,1,2,5][6,3,4,1,2,5] and split it into [6,3][6,3] and [4,1,2,5][4,1,2,5]. Then we write l1=6๐‘™1=6 and r1=5๐‘Ÿ1=5, and the arrays we have are [6,3][6,3] and [4,1,2,5][4,1,2,5];choose the array [4,1,2,5][4,1,2,5] and split it into [4,1,2][4,1,2] and [5][5]. Then we write l2=4๐‘™2=4 and r2=5๐‘Ÿ2=5, and the arrays we have are [6,3][6,3], [4,1,2][4,1,2] and [5][5];choose the array [4,1,2][4,1,2] and split it into [4][4] and [1,2][1,2]. Then we write l3=4๐‘™3=4 and r3=2๐‘Ÿ3=2, and the arrays we have are [6,3][6,3], [4][4], [1,2][1,2] and [5][5].You are given two integers n๐‘› and q๐‘ž, and two sequences [l1,l2,โ€ฆ,lq][๐‘™1,๐‘™2,โ€ฆ,๐‘™๐‘ž] and [r1,r2,โ€ฆ,rq][๐‘Ÿ1,๐‘Ÿ2,โ€ฆ,๐‘Ÿ๐‘ž]. A permutation of size n๐‘› is called valid if we can perform q๐‘ž operations and produce the given sequences [l1,l2,โ€ฆ,lq][๐‘™1,๐‘™2,โ€ฆ,๐‘™๐‘ž] and [r1,r2,โ€ฆ,rq][๐‘Ÿ1,๐‘Ÿ2,โ€ฆ,๐‘Ÿ๐‘ž].Calculate the number of valid permutations.InputThe first line contains two integers n๐‘› and q๐‘ž (1โ‰คq<nโ‰ค3โ‹…1051โ‰ค๐‘ž<๐‘›โ‰ค3โ‹…105).The second line contains q๐‘ž integers l1,l2,โ€ฆ,lq๐‘™1,๐‘™2,โ€ฆ,๐‘™๐‘ž (1โ‰คliโ‰คn1โ‰ค๐‘™๐‘–โ‰ค๐‘›).The third line contains q๐‘ž integers r1,r2,โ€ฆ,rq๐‘Ÿ1,๐‘Ÿ2,โ€ฆ,๐‘Ÿ๐‘ž (1โ‰คriโ‰คn1โ‰ค๐‘Ÿ๐‘–โ‰ค๐‘›).Additional constraint on the input: there exists at least one permutation which can produce the given sequences [l1,l2,โ€ฆ,lq][๐‘™1,๐‘™2,โ€ฆ,๐‘™๐‘ž] and [r1,r2,โ€ฆ,rq][๐‘Ÿ1,๐‘Ÿ2,โ€ฆ,๐‘Ÿ๐‘ž].OutputPrint one integer โ€” the number of valid permutations, taken modulo 998244353998244353.ExamplesinputCopy6 36 4 45 5 2outputCopy30inputCopy10 1109outputCopy1814400inputCopy4 124outputCopy8

Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.Return the largest sum of the given array after partitioning. Test cases are generated so that the answer fits in a 32-bit integer.ย Example 1:Input: arr = [1,15,7,9,2,5,10], k = 3Output: 84Explanation: arr becomes [15,15,15,9,10,10,10]

Make PermutationChef has an array ๐ดA of size ๐‘N. He wants to make a permutationโ€ โ€  using this array.Find whether there exists an array ๐ตB consisting of ๐‘N non-negative integers, such that the array ๐ถC constructed as ๐ถ๐‘–=๐ด๐‘–+๐ต๐‘–C iโ€‹ =A iโ€‹ +B iโ€‹ is a permutation.โ€ โ€  A permutation of size ๐‘N is an array of ๐‘N distinct elements in the range [1,๐‘][1,N]. For example, [4,2,1,3][4,2,1,3] is a permutation of size 44, while [3,2,2,1][3,2,2,1] and [1,3,4][1,3,4] are not.Input FormatThe first line of input will contain a single integer ๐‘‡T, denoting the number of test cases.Each test case consists of multiple lines of input.The first line of each test case consists of ๐‘N - the size of the array ๐ดAThe next line contains ๐‘N space-separated integers - ๐ด1,๐ด2,โ€ฆ,๐ด๐‘A 1โ€‹ ,A 2โ€‹ ,โ€ฆ,A Nโ€‹ - the elements of array ๐ดA.Output FormatFor each test case, output YES if there exists an array ๐ตB such that array ๐ถC constructed as ๐ถ๐‘–=๐ด๐‘–+๐ต๐‘–C iโ€‹ =A iโ€‹ +B iโ€‹ is a permutation, otherwise output NO.You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical).Constraints1โ‰ค๐‘‡โ‰ค1001โ‰คTโ‰ค1001โ‰ค๐‘โ‰ค1001โ‰คNโ‰ค1001โ‰ค๐ด๐‘–โ‰ค๐‘1โ‰คA iโ€‹ โ‰คNSample 1:InputOutput454 1 3 2 152 4 3 4 21161 1 1 1 6 6YESNOYESNOExplanation:Test case 11 : Consider ๐ต=[0,4,0,0,0]B=[0,4,0,0,0]. The corresponding array ๐ถC becomes [4,5,3,2,1][4,5,3,2,1], which is a permutation. Some other possible values of ๐ตB for which ๐ถC is a permutation are [1,0,1,1,1][1,0,1,1,1] and [1,3,0,0,0][1,3,0,0,0].Test case 22 : It can be proven that no valid array ๐ตB exists.

Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.ย Example 1:Input: nums = [1,2,3]Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]Example 2:Input: nums = [0,1]Output: [[0,1],[1,0]]Example 3:Input: nums = [1]Output: [[1]]ย Constraints:1 <= nums.length <= 6-10 <= nums[i] <= 10All the integers of nums are unique.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.