#P7244. 章节划分

    ID: 7996 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP数学线段树树状数组O2优化ST 表

章节划分

Background

  During essay week, as the name suggests, you write one essay a day, producing a lot of work.

  Xiao Huimao’s essays have been “publicly executed” by the teacher countless times. Yesterday, her own grandma turned into someone else’s “maternal grandma” in another essay; today, the noodles she finally managed to write about became someone else’s hot and sour rice noodles tomorrow. Once you use your material, it is basically ruined, qwq.

  So, unwilling to give up, Xiao Huimao decided to be even more productive.

Problem Description

Tianyi has decided on nn pieces of material, and they will be written in order in the essay. The theme feature value of the ii-th piece of material is aia_i.

However, Tianyi found that her masterpiece is far too long, so she wants to split them into exactly kk chapters. Each chapter contains a contiguous and non-empty segment of materials. Suppose the ii-th chapter contains materials [li,ri][l_i,r_i]. Tianyi will choose the material with the largest theme feature value to refine the idea, obtaining the theme value bib_i of this chapter, satisfying bi=maxi[li,ri]{ai}b_i=\max\limits_{i\in[l_i,r_i]}\{a_i\}.

Finally, the conciseness of the whole essay is the greatest common divisor of the theme values of all chapters, i.e., gcdi[1,k]{bi}\gcd\limits_{i\in[1,k]}\{b_i\}.

Tianyi of course wants to maximize the conciseness of the essay. What is the maximum possible value of the conciseness?


Simplified statement

Given a sequence aa of length nn, you must split it into exactly kk contiguous and non-empty segments. Define the theme value of the ii-th segment as the maximum of all elements in that segment, denoted by bib_i. You need to maximize gcdi[1,k]{bi}\gcd\limits_{i\in[1,k]}\{b_i\} and output this maximum value.

Input Format

The first line contains two integers n,kn,k, representing the length of the materials and the number of chapters to split into.

The second line contains nn integers, representing the theme feature value of each piece of material.

Output Format

Output one integer in a single line, representing the answer.

5 3
1 3 2 9 6
3
5 2
10 2 5 5 5
5

Hint

Sample explanation 1

There may be multiple optimal ways to split the materials. Here is one optimal split: divide these 55 materials into 33 chapters: [1,3],[2,9],[6][1,3],[2,9],[6]. Then b1=3,b2=9,b3=6b_1=3,b_2=9,b_3=6, and the maximum conciseness is gcd(3,9,6)=3\gcd(3,9,6)=3.


Constraints and notes

This problem uses bundled testdata.

For 100%100\% of the testdata, 1kn1051\le k\le n\le 10^5, 1ai1061\le a_i\le 10^{6}.

Subtask Points nn kk aia_i
1 5 5\le 5 / /
2 10 102\le 10^2
3 / 22
4 15 33
5 20 3×103\le 3\times 10^3 /
6 10 / 2×102\le 2\times 10^2
7 30 /

Translated by ChatGPT 5