Advertisement
Guest User

Untitled

a guest
Jan 11th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. /*
  5.  
  6.  
  7. █▒▒▒▒▒▒▒▒▒
  8. 10%
  9. ███▒▒▒▒▒▒▒
  10. 30%
  11. █████▒▒▒▒▒
  12. 50%
  13. ███████▒▒▒
  14. 70%
  15. ██████████
  16. 100%
  17.  
  18. .
  19. ☁☁☁☁☁☁☁⚡
  20. ☁☁☁☁☁☁⚡☁
  21. ☁☁☁☁☁⚡⚡☁
  22. ☁☁☁☁⚡⚡☁☁
  23. ☁☁☁⚡⚡☁☁☁
  24. ☁☁⚡⚡⚡☁☁☁
  25. ☁⚡⚡⚡☁☁☁☁
  26. ⚡⚡⚡⚡⚡⚡⚡⚡
  27. ⚡⚡⚡⚡⚡⚡⚡⚡
  28. ☁☁☁☁⚡⚡⚡☁
  29. ☁☁☁⚡⚡⚡☁☁
  30. ☁☁☁⚡⚡☁☁☁
  31. ☁☁⚡⚡☁☁☁☁
  32. ☁⚡⚡☁☁☁☁☁
  33. ☁⚡☁☁☁☁☁☁
  34. ⚡☁☁☁☁☁☁☁
  35.  
  36. ▀█▀ █░░ █▀▀ █▀ █░░ ▄▀▄ ▄▀▀ █░░ █▄░█ █▀▀ █░░░█ ▒█▀▀ ▒▄█░
  37. ░█░ █▀▄ █▀▀ █▀ █░▄ █▀█ ░▀▄ █▀▄ █░▀█ █▀▀ █░█░█ ▒▀▀▄ ░▒█░
  38. ░▀░ ▀░▀ ▀▀▀ ▀░ ▀▀▀ ▀░▀ ▀▀░ ▀░▀ ▀░░▀ ▀▀▀ ░▀░▀░ ▒▄▄▀ ▒▄█▄
  39.  
  40. */
  41.  
  42. const int N = 1e6;
  43. #define int long long
  44. map <int, int> newpos, mp;
  45. vector <int > g[N];
  46.  
  47. main()
  48. {
  49. ios_base::sync_with_stdio(0);
  50. cin.tie(0);
  51. string s, s1;
  52. cin >> s;
  53. set <char> kol;
  54. for (int i = 0; i < s.size(); i++) {
  55. kol.insert(s[i]);
  56. newpos[i] = i;
  57. mp[i] = i;
  58. }
  59. if (kol.size() == 1) {
  60. cout << 0 << "\n";
  61. cout.flush();
  62. cout << s;
  63. cout.flush();
  64. return 0;
  65. }
  66. vector <pair <int, int> > ask;
  67. for (int i = 0; i < s.size(); i++) {
  68. for (int j = i + 1; j < s.size(); j++) {
  69. if (s[i] != s[j]) {
  70. g[i].push_back(j);
  71. ask.push_back({i + 1, j + 1});
  72. }
  73. }
  74. }
  75. cout << ask.size() << "\n";
  76. cout.flush();
  77. for (auto to : ask) {
  78. cout << to.first << ' ' << to.second << "\n";
  79. cout.flush();
  80. }
  81. string bin;
  82. cin >> bin;
  83.  
  84. int i = 0, j = 0;
  85. while (i < ask.size()) {
  86. int i1 = 0;
  87. while (i < ask.size() && i1 < g[j].size()) {
  88. if (bin[i] == '1') {
  89.  
  90. if (mp[j] > mp[ask[i].second - 1]) {
  91. //cout << "kek";
  92. int po = mp[ask[i].second - 1], x = mp[j];
  93. char c2 = s[po];
  94. for (int z = mp[ask[i].second - 1]; z < mp[j]; z++) {
  95. int po1 = newpos[z + 1];
  96. newpos[z] = po1;
  97. s[z] = s[z + 1];
  98. mp[po1] = z;
  99. }
  100. s[x] = c2;
  101. newpos[x] = po;
  102. mp[po] = x;
  103. }
  104. }
  105. else {
  106. if (mp[j] < mp[ask[i].second - 1]) {
  107. int po = mp[ask[i].second - 1], x = mp[j];
  108. char c2 = s[po];
  109. for (int z = mp[ask[i].second - 1]; z > mp[j]; z--) {
  110. int po1 = newpos[z - 1];
  111. newpos[z] = po1;
  112. s[z] = s[z - 1];
  113. mp[po1] = z;
  114. }
  115. s[x] = c2;
  116. newpos[x] = po;
  117. mp[po] = x;
  118. }
  119. }
  120. i++;
  121. i1++;
  122. }
  123. j++;
  124. }
  125. string ans = s;
  126. cout << ans;
  127. cout.flush();
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement