luogu#P10861. [HBCPC2024] MACARON Likes Happy Endings

[HBCPC2024] MACARON Likes Happy Endings

题目描述

MACARON is going to read a book, which contains nn chapters, and the ii-th chapter has aia_i characters. MACARON wants to read this book in the next kk days. On each day, he either reads several chapters from the first unread chapter, or just takes a rest (does not read the book), but he should finish his reading in kk days.

MACARON enjoys his reading time and likes happy endings, so he does not want to be too sad during these days. He has an unlucky number dd, because he thinks number dd will lead to a bad ending. We use a sadness value to quantify his mood on each day. On the ii-th day, if he reads, suppose that he reads chapters from LiL_i to RiR_i. The sadness value of this day is the number of intervals [l,r][l, r] such that LilrRiL_i\leq l\leq r\leq R_i and i=lrai=d\bigoplus_{i=l}^r a_i=d. The \oplus denotes the bitwise XOR operator. If he doesn't read, let the sadness value be 00.

MACARON wants to arrange his reading schedule to minimize the sum of sadness value in kk days. Can you help him find the minimum value?

输入格式

The first line contains three integers n,kn, k and dd ($1\leq n\leq 10^5, 1\leq k\leq \min(n, 20), 0\leq d\leq 10^6$) --- the number of chapters, the days for reading, and the unlucky number.

The second line contains nn integers aia_i (0ai1060\leq a_i\leq 10^6) --- the number of characters in each chapter.

输出格式

Output a single integer denoting the minimized sum of the sadness value.

10 4 5
1 2 3 4 5 5 6 5 4 3
3

提示

Here is an optimal schedule for reading:

  • on the first day, just take a rest, and the sadness value is 0;
  • on the second day, read from chapter 1 to chapter 3, and the sadness value is 0;
  • on the third day, read from chapter 4 to chapter 7, and the sadness value is 2;
  • on the fourth day, read from chapter 8 to chapter 10, and the sadness value is 1.