#SRD0000150. Truy vấn hoán vị đoạn (Range Shuffle Query)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Truy vấn hoán vị đoạn (Range Shuffle Query)
Range Shuffle Query
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array . Each query provides and considers a sequence initially equal to .
Perform the following procedure exactly once:
- Remove every element of whose value is at least .
- Rearrange the remaining elements in any order.
Count the number of distinct resulting value sequences. Different permutations of equal-valued elements count only once. If no element remains, the empty sequence counts as one possibility. Output the count modulo .
The original array is unchanged, and all queries are independent.
Input
- First line: .
- Second line: the array elements .
- Each of the next lines: .
Output
Print lines. Line gives the number of distinct sequences for query , modulo .
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; modulo .
- Subtask 2 (30 points): ; ; ; ; ; modulo .
- Subtask 3 (50 points): ; ; ; ; ; modulo .
Examples
Example 1
Input
5 3
1 2 3 3 1
1 5 3
3 4 1
1 3 4
Output
3
1
6
Explanation
Query keeps and produces , , : three distinct sequences. Query removes both elements, leaving one empty sequence. Query keeps , all distinct, so sequences.