Advertisement
GerONSo

Untitled

Jun 1st, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #define pragma
  2.  
  3. #ifdef pragma
  4. #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
  5. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  6. #endif // pragma
  7.  
  8. #include<bits/stdc++.h>
  9. #include <ext/pb_ds/assoc_container.hpp>
  10. #include <ext/pb_ds/tree_policy.hpp>
  11.  
  12. #define ll long long
  13. #define all(x) begin(x), end(x)
  14. #define pb push_back
  15. #define x first
  16. #define y second
  17. #define int long long
  18. #define zero(two) memset(two, 0, sizeof(two))
  19.  
  20. using namespace std;
  21. using namespace __gnu_pbds;
  22.  
  23.  
  24. typedef vector<int> vi;
  25. typedef vector<bool> vb;
  26. typedef pair<int, int> pii;
  27. typedef long double ld;
  28. typedef vector<vi> matrix;
  29. template<typename T>
  30. using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  31.  
  32. const ld PI = atan2(0, -1);
  33.  
  34. void seriy() {
  35. ios::sync_with_stdio(0);
  36. cin.tie(0);
  37. cout.tie(0);
  38. cout << fixed << setprecision(10);
  39. #if _offline
  40. freopen("input.txt", "r", stdin);
  41. freopen("output.txt", "w", stdout);
  42. #endif
  43. }
  44.  
  45. const int MAXN = 1e5 + 10;
  46. const int INF = 1e18 + 7;
  47. const int MAXLOG = 20;
  48. const int MOD = 998244353;
  49. const int BASE = 47;
  50.  
  51. signed main() {
  52. seriy();
  53. int n;
  54. cin >> n;
  55. vi a(n);
  56. for(int i = 0; i < n; i++) {
  57. cin >> a[i];
  58. a[i]--;
  59. }
  60. vector<pii> kek;
  61. for(int i = 0; i < n; i++) {
  62. if(i < n / 2) {
  63. while(a[i] >= n / 2) {
  64. kek.pb({a[i], i});
  65. swap(a[a[i]], a[i]);
  66. }
  67. }
  68. else {
  69. while(a[i] < n / 2) {
  70. kek.pb({a[i], i});
  71. swap(a[a[i]], a[i]);
  72. }
  73. }
  74. }
  75. for(int i = 0; i < n; i++) {
  76. int cur = i, need = a[i];
  77. if(cur != need) {
  78. if(i < n / 2) {
  79. kek.pb({i, n - 1});
  80. kek.pb({a[i], n - 1});
  81. kek.pb({i, n - 1});
  82. swap(a[cur], a[need]);
  83. }
  84. else {
  85. kek.pb({i, 0});
  86. kek.pb({a[i], 0});
  87. kek.pb({i, 0});
  88. swap(a[cur], a[need]);
  89. }
  90. }
  91. }
  92. cout << kek.size() << '\n';
  93. for(auto i : kek) {
  94. cout << i.x + 1 << " " << i.y + 1 << '\n';
  95. }
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement