#SRD0000131. Phân hoạch cô lập (Isolation)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phân hoạch cô lập (Isolation)
Isolation
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Partition an array into any number of disjoint, nonempty, contiguous segments covering the entire array in their original order. A partition is valid when each segment contains at most distinct values occurring exactly once in that segment.
For example, in , the values occurring exactly once are and , so the number of singleton values is two.
Count valid partitions modulo .
Input
- The first line contains .
- The second line contains .
Output
Print the number of valid partitions modulo .
Subtasks
- Subtask 1 (10 points): , .
- Subtask 2 (20 points): , .
- Subtask 3 (30 points): , .
- Subtask 4 (40 points): , (original full constraints).
Examples
Example 1
Input
3 1
1 1 2
Output
3
Explanation: The valid cuts are , and . The partition is invalid because the last segment has two singleton values.
Example 2
Input
5 2
1 1 2 1 3
Output
14
Explanation: There are possible choices of cut positions. Exactly satisfy the bound on singleton values for every segment.
Example 3
Input
5 5
1 2 3 4 5
Output
16
Explanation: Every segment has at most five singleton values, so all partitions are valid.