fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int n;
  9. cin >> n;
  10. vector<int> P(n);
  11. for (int i = 0; i < n; i++) cin >> P[i];
  12.  
  13. // 역전 개수의 parity 구하기
  14. long long inv = 0;
  15. for (int i = 0; i < n; i++) {
  16. for (int j = i+1; j < n; j++) {
  17. if (P[i] > P[j]) inv++;
  18. }
  19. }
  20.  
  21. long long total = 1LL * n * (n-1) / 2;
  22.  
  23. if ((inv % 2) != (total % 2)) {
  24. cout << 0 << "\n";
  25. return 0;
  26. }
  27.  
  28. cout << 1 << "\n";
  29. // 교환 순서 아무거나: 예를 들어 (i,j) with i<j 사전순 출력
  30. for (int j = 2; j <= n; j++) {
  31. for (int i = 1; i < j; i++) {
  32. cout << i << " " << j << "\n";
  33. }
  34. }
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5272KB
stdin
3
1 3 2
stdout
1
1 2
1 3
2 3