排序后与原数组比较,同一位置上的数奇偶性不变。
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader();
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int[] a = new int[n], b = new int[n];
for(int i = 0; i < n; ++i)
a[i] = b[i] = in.nextInt();
Arrays.sort(a);
boolean flag = true;
for(int i = 0; i < n; ++i) {
if(a[i] % 2 != b[i] % 2) {
flag = false; break;
}
}
out.println(flag ? "Yes" : "No");
out.close();
}
}
class InputReader{BufferedReader buf;StringTokenizer tok;InputReader(){buf = new BufferedReader(new InputStreamReader(System.in));}boolean hasNext(){while (tok == null || !tok.hasMoreElements()){try{tok = new StringTokenizer(buf.readLine());}catch (Exception e){return false;}}return true;}String next(){if (hasNext())
return tok.nextToken();return null;}int nextInt(){return Integer.parseInt(next());}long nextLong(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}BigInteger nextBigInteger(){return new BigInteger(next());}BigDecimal nextBigDecimal(){return new BigDecimal(next());}}