fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define all(ac) ac.begin(),ac.end()
  4. #define task "tet"
  5. #define fi first
  6. #define se second
  7. #define pii pair<int,int>
  8. #define db long double
  9. #define int long long
  10.  
  11. void pre_calc(vector <char> &c, vector <int> &cnt, string s) {
  12. int cur = 0;
  13. for(char x : s) {
  14. if(x >= '0' && x <= '9') cur = cur * 10 + x - '0';
  15. else {
  16. if(cur > 0) cnt.emplace_back(cur);
  17. c.emplace_back(x);
  18. cur = 0;
  19. }
  20. }
  21. if(cur > 0) cnt.emplace_back(cur);
  22. return;
  23. }
  24.  
  25. int all_val(string s) {
  26. int res = 0;
  27. int cur = 0;
  28. for(char x : s) {
  29. if(x >= '0' && x <= '9') cur = cur * 10 + x - '0';
  30. else {
  31. res += cur;
  32. cur = 0;
  33. }
  34. }
  35. return res + cur;
  36. }
  37.  
  38. void AC_Quan(vector <char> &c, vector <int> &cnt, vector <char> &ca, vector <int> &cnta) {
  39. int n = ca.size();
  40. for(int i=0;i<n;i++) {
  41. char temp = ca[i];
  42. int tcnt = 0;
  43. while(i < n) {
  44. if(ca[i] == temp) tcnt += cnta[i], i++;
  45. else break;
  46. }
  47. if(tcnt != 0) {
  48. c.emplace_back(temp);
  49. cnt.emplace_back(tcnt);
  50. }
  51. if(i == n) break;
  52. i--;
  53. }
  54. return;
  55. }
  56.  
  57. void solve_type4(string a, string b, int p) {
  58. vector <char> ca, cb;
  59. vector <int> cnta, cntb;
  60. pre_calc(ca, cnta, a);
  61. pre_calc(cb, cntb, b);
  62.  
  63. vector <char> cans;
  64. vector <int> cntans;
  65. bool ok = true;
  66. for(int i=0;i<ca.size();i++) {
  67. if(p <= cnta[i] + 1 && ok == true) {
  68. if(p == cnta[i] + 1) {
  69. cans.emplace_back(ca[i]);
  70. cntans.emplace_back(cnta[i]);
  71. for(int j=0;j<cb.size();j++) {
  72. cans.emplace_back(cb[j]);
  73. cntans.emplace_back(cntb[j]);
  74. }
  75. }
  76. else {
  77. int l = p - 1;
  78. int r = cnta[i] - p + 1;
  79. cans.emplace_back(ca[i]);
  80. cntans.emplace_back(l);
  81. for(int j=0;j<cb.size();j++) {
  82. cans.emplace_back(cb[j]);
  83. cntans.emplace_back(cntb[j]);
  84. }
  85. cans.emplace_back(ca[i]);
  86. cntans.emplace_back(r);
  87. }
  88. ok = false;
  89. }
  90. else {
  91. p -= cnta[i];
  92. cans.emplace_back(ca[i]);
  93. cntans.emplace_back(cnta[i]);
  94. }
  95. }
  96.  
  97. vector <char> fc;
  98. vector <int> fcnt;
  99. AC_Quan(fc, fcnt, cans, cntans);
  100.  
  101. for(int i=0;i<fc.size();i++) cout << fc[i] << fcnt[i];
  102. cout << '\n';
  103. return;
  104. }
  105.  
  106. vector <char> c1;
  107. vector <int> cnt1;
  108. int hmt = 0;
  109.  
  110. void solve_type3(string &s, int p, int c, int cp) {
  111. vector <char> cans, ca;
  112. vector <int> cntans, cnta;
  113.  
  114. pre_calc(ca, cnta, s);
  115.  
  116. for(int i=0;i<ca.size();i++) {
  117. if(p <= cnta[i]) {
  118. cans.emplace_back(ca[i]);
  119. cntans.emplace_back(min(c, cnta[i] - p + 1));
  120. c -= cntans[0];
  121. i++;
  122. while(true) {
  123. if(c == 0) break;
  124. cans.emplace_back(ca[i]);
  125. cntans.emplace_back(min(c, cnta[i]));
  126. c -= cntans.back();
  127. i++;
  128. }
  129. break;
  130. }
  131. else p -= cnta[i];
  132. }
  133.  
  134. if(cp == 0) {
  135. if(hmt == 0) c1 = cans, cnt1 = cntans;
  136. else
  137. if(hmt == 1) {
  138. vector <int> nxcn;
  139. vector <char> nxch;
  140. int pos = 0;
  141. for(int i=0;i<c1.size();i++) {
  142. nxch.emplace_back(c1[i]);
  143. nxcn.emplace_back(cnt1[i]);
  144. pos += cnt1[i];
  145. }
  146.  
  147. for(int i=0;i<cans.size();i++) {
  148. nxch.emplace_back(cans[i]);
  149. nxcn.emplace_back(cntans[i]);
  150. }
  151. vector <char> ress;
  152. vector <int> cc;
  153. AC_Quan(ress, cc, nxch, nxcn);
  154. for(int i=0;i<ress.size();i++) cout << ress[i] << cc[i];
  155. cout << '\n';
  156. }
  157. hmt++;
  158. return;
  159. }
  160.  
  161. for(int i=0;i<cans.size();i++) cout << cans[i] << cntans[i];
  162. cout << '\n';
  163. return;
  164. }
  165.  
  166. int32_t main() {
  167. ios::sync_with_stdio(false);
  168. cin.tie(0), cout.tie(0);
  169.  
  170. string type;
  171. while(cin >> type) {
  172. if(type == "@1") {
  173. cout << type << ": ";
  174. string a, b; cin >> a >> b;
  175. solve_type4(a, b, all_val(a) + 1);
  176. }
  177. else
  178. if(type == "@4") {
  179. cout << type << ": ";
  180. string a, b; cin >> a >> b;
  181. int p; cin >> p;
  182. solve_type4(a, b, p);
  183. }
  184. else
  185. if(type == "@2") {
  186. cout << type << ": ";
  187. string s; cin >> s;
  188. int p, c; cin >> p >> c;
  189. hmt = 0;
  190. solve_type3(s, 1, p - 1, 0);
  191. solve_type3(s, p + c, all_val(s) - p - c + 1, 0);
  192. }
  193. else
  194. if(type == "@3") {
  195. cout << type << ": ";
  196. string s; cin >> s;
  197. int p, c; cin >> p >> c;
  198. solve_type3(s, p, c, 1);
  199. }
  200. }
  201. return 0;
  202. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty