https://www.hackerrank.com/challenges/larrys-array/problem
https://www.hackerrank.com/challenges/larrys-array/forum/comments/124313
思路:对于奇数长度的数组,rotate一次不改变逆序对的奇偶性;rotate偶数长度会改变
而拍完序后的逆序对为0
# Complete the larrysArray function below.
def larrysArray(a,n):
res=0
for i in range(n):
for j in range(i+1,n):
if a[j]<a[i]: res+=1
return 'YES' if res%2==0 else 'NO'
if __name__ == '__main__':
t = int(input())
for t_itr in range(t):
n = int(input())
A = list(map(int, input().rstrip().split()))
result = larrysArray(A,n)
print(result)