AtCoder Beginner Contest 072
翻译中…
Problem Statement
翻译中…
You are given a permutation $p_1,p_2,...,p_N$ consisting of $1$,$2$,..,$N$. You can perform the following operation any number of times (possibly zero):
翻译中…
Operation: Swap two adjacent elements in the permutation.
翻译中…
You want to have $p_i ≠ i$ for all $1≤i≤N$. Find the minimum required number of operations to achieve this.
翻译中…
Constraints
翻译中…
$2≤N≤10^5$$p_1,p_2,..,p_N$is a permutation of$1,2,..,N$.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
N
p_1 p_2 .. p_N
翻译中…
Output
翻译中…
Print the minimum required number of operations
翻译中…
样例
Input #1
5
1 4 3 5 2
Output #1
2
Swap $1$ and $4$, then swap $1$ and $3$. $p$ is now $4,3,1,5,2$ and satisfies the condition. This is the minimum possible number, so the answer is $2$.
Input #2
2
1 2
Output #2
1
Swapping $1$ and $2$ satisfies the condition.
Input #3
2
2 1
Output #3
0
The condition is already satisfied initially.
Input #4
9
1 2 4 9 5 8 7 3 6
Output #4
3
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。