fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. public class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner sc = new Scanner(System.in);
  10. int t =sc.nextInt();
  11. for(int i=0;i<t;i++){
  12. int n = sc.nextInt();
  13. int [] arr = new int[n];
  14. for(int j=0;j<n;j++){
  15. arr[j]=sc.nextInt();
  16. }
  17. int isSorted = 1;
  18. for(int j=0;j<=(n/2)-1;j++){
  19. if(arr[j]==j+1){
  20. continue;
  21. }
  22. else{
  23. if(arr[((j+1)*2)-1]==j+1 && arr[j]==((j+1)*2)){
  24. continue;
  25. }
  26. else{
  27. isSorted = 0;
  28. break;
  29. }
  30. }
  31. }
  32. if(isSorted==1){
  33. System.out.println("YES");
  34. }
  35. else{
  36. System.out.println("NO");
  37. }
  38. }
  39. }
  40. }
Success #stdin #stdout 0.14s 56584KB
stdin
2
5
1 4 3 2 5
5
1 4 2 3 5
stdout
YES
NO