#P10843. 【MX-J2-T4】Turtle and Cycles
【MX-J2-T4】Turtle and Cycles
Background
Original link: https://oier.team/problems/J2E.
Problem Description
You are given a circular permutation of .
In one operation, you may choose an integer and set to .
A position is good if and only if and .
The circular sequence is good if and only if there exists exactly one position such that position is good.
Find the minimum number of operations needed to make good. It can be proven that a solution always exists.
Input Format
This problem has multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case:
The first line contains a positive integer .
The second line contains non-negative integers .
Output Format
For each test case, output one line containing one integer, the minimum number of operations.
3
2
1 0
5
2 3 0 4 1
10
0 5 9 7 3 1 6 4 8 2
0
1
5
Hint
Sample Explanation
In the first test case, the initial sequence has exactly one good position , so the answer is .
In the second test case, you can choose to perform an operation. After the operation, the sequence becomes . Now the sequence has exactly one good position , so the answer is .
Constraints
This problem uses bundled testdata and enables subtask dependencies.
| Subtask ID | Score | Special Property | Dependency | ||
|---|---|---|---|---|---|
| None | None | ||||
| None | |||||
| None | |||||
For all testdata, it holds that , , , and is a permutation of .
Translated by ChatGPT 5