AtCoder Regular Contest 102
F
Revenge of BBuBBBlesort!
AtCoder
⌀ 3464
原题
← E→
翻译中…

Problem Statement

翻译中…

You are given a permutation of $1,2,...,N$: $p_1,p_2,...,p_N$. Determine if the state where $p_i=i$ for every $i$ can be reached by performing the following operation any number of times:

翻译中…
  • Choose three elements $p_{i-1},p_{i},p_{i+1}$ ($2\leq i\leq N-1$) such that $p_{i-1}>p_{i}>p_{i+1}$ and reverse the order of these three.
翻译中…

Constraints

翻译中…
  • $3 \leq N \leq 3 × 10^5$
  • $p_1,p_2,...,p_N$ is a permutation of $1,2,...,N$.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
p_1
:
p_N

翻译中…

Output

翻译中…

If the state where $p_i=i$ for every $i$ can be reached by performing the operation, print Yes; otherwise, print No.

翻译中…

样例

Input #1
5
5
2
1
4
3
Output #1
Yes
The state where $p_i=i$ for every $i$ can be reached as follows: - Reverse the order of $p_1,p_2,p_3$. The sequence $p$ becomes $1,2,5,4,3$. - Reverse the order of $p_3,p_4,p_5$. The sequence $p$ becomes $1,2,3,4,5$.
Input #2
4
3
2
4
1
Output #2
No
Input #3
7
3
2
1
6
5
4
7
Output #3
Yes
Input #4
6
5
3
4
1
2
6
Output #4
No
题目信息
题号
arc102_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。