#P14808. [CCPC 2024 哈尔滨站] 子序列计数
[CCPC 2024 哈尔滨站] 子序列计数
Description
Given a sequence of length and a sequence of length , where is composed of consecutive segments from left to right. The -th segment contains identical elements, each with a value of .
The sequence is formed by shuffling the sequence according to a certain rule. Specifically, the sequence satisfies (indices start from ). Here, is a given positive integer constant, and it is guaranteed that .
Find the number of times appears as a subsequence in . Formally, if there is a strictly increasing sequence of indices such that for each , , then is considered a subsequence of at these indices. You need to determine how many different index groups satisfy this condition. Since the answer may be large, output the result modulo .
Input Format
The first line contains four integers (, , , ).
The second line contains integers representing the sequence ().
The next lines describe the sequence , each containing two integers (, ). It is guaranteed that .
Output Format
Output a single integer, representing the result modulo .
4 2 17 27
3 1
10 3
6 1
10 3
1 1
76
5 3 1789 15150
555 718 726
72 555
1029 718
5807 726
1002 718
7240 555
390415327
京公网安备 11011102002149号