Advertisement
mfgnik

Untitled

Dec 13th, 2020
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. from collections import defaultdict
  2.  
  3.  
  4. n = int(input())
  5. numbers = list(enumerate(map(int, input().split())))
  6. permutations = {}
  7. positions = defaultdict(set)
  8. for index in range(n):
  9.     positions[numbers[index][1]].add(index)
  10. numbers.sort(key=lambda x: x[1])
  11. result = True
  12. print(numbers)
  13. print(positions)
  14. for index in range(n):
  15.     if numbers[index][0] == index:
  16.         continue
  17.     second_index = numbers[index][0]
  18.     print(second_index, result)
  19.     value = numbers[second_index][1]
  20.     if index in positions[value]:
  21.         if index > second_index:
  22.             permutations[index] = second_index
  23.     else:
  24.         result = False
  25. if result:
  26.     print("Yes")
  27.     print(len(permutations))
  28.     for index, second_index in permutations.items():
  29.         print(index + 1, second_index + 1)
  30. else:
  31.     print("No")
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement