P27924 [洛谷] [Language Monthly Contest 202404] Mysterious Permutation
普及
题目描述

Problem Description

A sequence is considered a mysterious sequence if and only if it meets the following conditions:

  1. The sequence is a permutation. That is, each integer from $1$ to $n$ appears exactly once in the sequence (for example, when $n=4$, $1,2,4,3$ is a permutation, but $1,2,2,2$ is not);
  2. We denote the position of $x$ in the sequence (which position it appears in) as $p_x$ ($1 \leq p_x \leq n$). A mysterious sequence must satisfy that for any integer $i$ from $1$ to $n$, $p_i = a_i$.

For example, for the sequence $3, 5, 2, 1, 4$, the position of $1$ is $4$, so $p_1 = 4$. However, $a_1 = 3 \neq p_1$, so this sequence is not a mysterious sequence.

Your task is to determine whether a given sequence $a_1, a_2, \cdots, a_n$ is a mysterious sequence.

Input Format

The first line contains an integer $n$, representing the length of the sequence.
The second line contains $n$ integers $a_1, a_2, \cdots, a_n$.

Output Format

A string: if the sequence is a mysterious sequence, output YES; otherwise, output NO.

Sample Input and Output

Sample Input #1

3
2 1 3

Sample Output #1

YES

Sample Input #2

5
3 5 2 1 4

Sample Output #2

NO

Notes

Data Size and Constraints

For $40\%$ of the data, $1 \leq n \leq 100$.

For $70\%$ of the data, $1 \leq n \leq 2000$.

For $100\%$ of the data, $1 \leq n \leq 10^5$.

The data guarantees that $a$ is a permutation. That is, each integer from $1$ to $n$ appears exactly once in the sequence.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2 1 3
样例输出
YES