## A. Life of a Flower

### Solution:

Just simulate according to the description of the problem.

Java

C++

## B. Array Eversion

### Solution:

Obviously, when the maximum value is at the right end of the array, the array no longer changes.
After each operation, the rightmost value will become the first number from right to left that is greater than the current rightmost value.

Therefore, we only need to find out how many operations have passed before the rightmost value becomes the maximum value of the array.

Java

C++

## C. Minimize Distance

### Solution:

Obviously, except to the last delivery, each delivery will need to return to the origin. Therefore, the last delivery should be as far as possible.
At the same time, delivery to the furthest place should be as full as possible.

Therefore, we take the goods back and forth from far to near, and finally we subtract the distance of the last return with the goods.

Java

C++

## D. Yet Another Sorting Problem

### Solution:

First of all, if there are duplicate numbers, then we can achieve the interchange position of the two numbers by adding two identical numbers and a different number. Therefore, if there are the same numbers, it must be YES.

And for the case where there is no repeated number. We can observe that after each operation, the number of reversed pairs of the array will only change by 2. For example, [1,2,3,4,5], after we perform operations on 2,3,4, it becomes [1,4,2,3,5], and the number of reverse pairs has changed from 0 to 2.
Therefore, we only need to use the segment tree to maintain the number of reverse-order pairs. If the number is even, then YES, otherwise NO.

Java

C++