#P10235. [yLCPC2024] C. 舞萌基本练习

    ID: 11511 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>二分树状数组洛谷原创洛谷月赛

[yLCPC2024] C. 舞萌基本练习

Problem Description

While playing MaiMai dx, Fusu found that a song can be split into at most kk segments for separate practice.

Specifically, the song has nn notes, and each note has a difficulty value. The difficulty of the ii-th note is aia_i. Fusu thinks that the notes in a segment should become as difficult as possible. Therefore, for an interval [l,r][l, r] of the note sequence, she defines the “non-beauty” of this interval as the number of inversion pairs in this interval.

The number of inversion pairs in an interval [l,r][l, r] is defined as the number of pairs (i,j)(i, j) such that li<jrl \leq i < j \leq r and ai>aja_i > a_j.

Fusu wants to partition the song into at most kk subsegments, so that every note belongs to at least one subsegment, and the maximum non-beauty among all segments is as small as possible.

Formally, you need to split it into tkt \leq k intervals [l1,r1],[l2,r2],[lt,rt][l_1, r_1], [l_2, r_2], \dots [l_t, r_t], satisfying:

  • l1=1l_1 = 1, rt=nr_t = n.
  • For 1i<t1 \leq i < t, ri+1=li+1r_i + 1 = l_{i + 1}.
  • For 1it1 \leq i \leq t, liril_i \leq r_i.

Let f(l,r)f(l, r) denote the non-beauty of interval [l,r][l, r]. Minimize maxi=1tf(li,ri)\max\limits_{i = 1}^t f(l_i, r_i).

Input Format

This problem contains multiple test cases within a single test file. The first line contains a positive integer TT, the number of test cases. For each test case:

The first line contains two integers n,kn, k (1kn1051 \leq k \leq n \leq 10^5), representing the number of notes in the song and the maximum number of segments.
The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (109ai109-10^9 \leq a_i \leq 10^9), representing the difficulty of each note.

It is guaranteed that the sum of nn over all test cases within a single test file does not exceed 10510^5.

Output Format

For each test case, output one line with one integer, representing the answer.

2
5 2
1 3 2 5 4
8 2
4 2 3 6 7 1 8 5
1
2

Hint

Translated by ChatGPT 5