PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000131. Phân hoạch cô lập (Isolation)

    ID: 2105 Loại: Thông thường 6000ms 256MiB Tried: 0 Đã chấp nhận: 0 Độ khó: 9 Đăng bởi: Nhãn>Dynamic programming basicsBottom-up DPSquare root decompositionModular arithmeticTime complexity
HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phân hoạch cô lập (Isolation)

Isolation

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Partition an array aa 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 kk distinct values occurring exactly once in that segment.

For example, in [2,2,5,7,7,8][2,2,5,7,7,8], the values occurring exactly once are 55 and 88, so the number of singleton values is two.

Count valid partitions modulo 998244353998244353.

Input

  • The first line contains n,kn,k.
  • The second line contains a1,…,ana_1,\ldots,a_n.

Output

Print the number of valid partitions modulo 998244353998244353.

Subtasks

  • Subtask 1 (10 points): 1≤k≤n≤181\le k\le n\le18, 1≤ai≤n1\le a_i\le n.
  • Subtask 2 (20 points): 1≤k≤n≤2 0001\le k\le n\le2\,000, 1≤ai≤n1\le a_i\le n.
  • Subtask 3 (30 points): 1≤k≤n≤20 0001\le k\le n\le20\,000, 1≤ai≤n1\le a_i\le n.
  • Subtask 4 (40 points): 1≤k≤n≤100 0001\le k\le n\le100\,000, 1≤ai≤n1\le a_i\le n (original full constraints).

Examples

Example 1

Input

3 1
1 1 2

Output

3

Explanation: The valid cuts are [1]∣[1]∣[2][1]\mid[1]\mid[2], [1,1]∣[2][1,1]\mid[2] and [1,1,2][1,1,2]. The partition [1]∣[1,2][1]\mid[1,2] 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 1616 possible choices of cut positions. Exactly 1414 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 24=162^4=16 partitions are valid.