Preparing NOJ

# Luka and Permutation

1000ms 65536K

## Description:

Luka has a sequence $p = { p_1, p_2, \cdots , p_N }$ which is a permutation of ${1, 2, \cdots, N}$.

However, there are some naughty numbers which is not at its position, that is to say, $p_i \neq i$. Luka is a perfectionist so he can choose two integers $i$ and $j$ ($1 \leq i < j \leq N$) and swap $p_i$ and $p_j$. But he is a little bit lazy so that he just want to do this operation once. Help him calculate if he can sort $p$ in ascending order.

## Input:

The first lines contains an integer $T$ means the number of test cases.

For each test case, the first line contains one integer $N$ describes the length of the sequence and the second line contain $N$ non-repeating integer forming sequence $p$.

Note that: $1 \leq T \leq 100$, $1 \leq N \leq 10^5$. And the sum of all $N$ would not exceed $10^6$.

## Output:

For each test case, output one single line of YES or NO.

## Sample Input:

2
5
1 3 2 4 5
5
2 3 1 5 4

## Sample Output:

YES
NO

Info

Provider NOJ

Code NOJ2385

Tags

Submitted 53

Passed 29

AC Rate 54.72%

Date 08/15/2019 01:18:45

Related

Nothing Yet