fork download
  1. #pragma GCC optimize("Ofast")
  2.  
  3. # include <iostream>
  4. # include <algorithm>
  5. # include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. char a[2500505];
  10. char b[2500505];
  11.  
  12. int main() {
  13. ios_base::sync_with_stdio(false);
  14. cin.tie(0);
  15.  
  16. cin >> a;
  17. int n = (int)strlen(a);
  18. memcpy(b, a, n);
  19. reverse(b, b + n);
  20. int q;
  21. cin >> q;
  22. while (q--) {
  23. int l, r;
  24. cin >> l >> r;
  25. swap_ranges(a + l - 1, a + r, b + n - r);
  26. }
  27. cout << a << endl;
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 20952KB
stdin
programmingcontest
5
4 8
11 14
2 9
5 16
5 13
stdout
pigrornnocgtemmast