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. long long inv = 0;
  14. for (int i = 0; i < n; i++) {
  15. for (int j = i+1; j < n; j++) {
  16. if (P[i] > P[j]) inv++;
  17. }
  18. }
  19.  
  20. long long total = 1LL * n * (n-1) / 2;
  21.  
  22. if ((inv % 2) != (total % 2)) {
  23. cout << 0 << "\n";
  24. return 0;
  25. }
  26.  
  27. cout << 1 << "\n";
  28. // 올바른 교환 순서: 왼쪽에서 오른쪽으로
  29. for (int i = 1; i <= n-1; i++) {
  30. for (int j = i+1; j <= n; j++) {
  31. cout << i << " " << j << "\n";
  32. }
  33. }
  34. }
Success #stdin #stdout 0s 5320KB
stdin
3
1 3 2
stdout
1
1 2
1 3
2 3