#P9376. 「DROI」Round 2 进制与操作
「DROI」Round 2 进制与操作
Background
Instead of writing a weak background, it is better to make a higher-quality problem.
Problem Description
Define one operation on a number in base as either of the following:
-
Set .
-
Set ,where .
You are given a sequence of length . There are queries, and each query is in the form:
l r Bmeans: for the numbers in the sequence with indices in , when operating in base , what is the minimum number of operations needed to make all numbers equal (note: each operation is applied to one number).
Queries are independent, i.e. the operations are not actually performed.
Input Format
The first line contains two integers, which are .
The second line contains numbers, representing the sequence .
The next lines each contain three numbers, representing for the query.
Output Format
Output lines in total. The -th line should contain the answer to the -th query.
5 5
7 6 5 8 9
1 3 2
2 5 2
4 4 6
3 5 4
1 5 3
5
8
0
5
10
8 4
10 14 7 11 19 13 7 18
1 7 4
3 8 2
1 4 4
1 4 2
15
18
8
11
Hint
Sample Explanation
For sample 1, for the five queries, making all numbers in the interval become , , , , and , respectively, is one optimal way.
Constraints
"This problem uses bundled testdata."
-
: .
-
: it is guaranteed that all queries have .
-
: .
-
: no special restrictions.
For of the testdata: , .
Translated by ChatGPT 5