fork download
  1. #pragma warning(disable:4786)
  2. #pragma warning(disable:4996)
  3. #include<bits/stdc++.h>
  4. #include <ext/pb_ds/assoc_container.hpp>
  5. #include <ext/pb_ds/trie_policy.hpp>
  6. #include<ext/pb_ds/detail/standard_policies.hpp>
  7. #include <ext/rope>
  8. #define pii pair<int,int>
  9. #define pll pair<long long ,long long>
  10. #define pli pair<long long , int>
  11. #define pil pair<int ,long long>
  12. #define pi acos(-1)
  13. #define pb push_back
  14. #define mkp make_pair
  15. #define all(a) a.begin(), a.end()
  16. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  17. #define ll long long
  18. #define MAX 300005
  19. #define INF 0x3f3f3f3f
  20. template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
  21. template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);} // M is prime}
  22.  
  23. using namespace std;
  24. using namespace __gnu_pbds;
  25. using namespace __gnu_cxx;
  26.  
  27. typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
  28. typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
  29. typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
  30.  
  31.  
  32.  
  33.  
  34. int main(){
  35. IOS
  36. //freopen("output.txt","w",stdout);
  37. string s;
  38. cin>>s;
  39. string t(s.rbegin(),s.rend());
  40. rope<char>rop,rop2;
  41.  
  42. for(int i=0;i<s.length();i++){
  43. rop.pb(s[i]);
  44. rop2.pb(t[i]);
  45. }
  46.  
  47. int q;
  48. cin>>q;
  49.  
  50. for(int tt=0;tt<q;tt++){
  51.  
  52. int type;
  53. cin>>type;
  54. if(type==1){
  55. int x,y;
  56. cin>>x>>y;
  57. if(x>y)swap(x,y);
  58. if(x==0 && y==s.length()-1)continue;
  59. auto temp = rop.substr(x,y-x+1);
  60. rop.erase(x,y-x+1);
  61.  
  62. x = s.length()-x-1;
  63. y = s.length()-y-1;
  64. if(x<y)swap(x,y);
  65. auto temp2 = rop2.substr(y,x-y+1);
  66. rop2.erase(y,x-y+1);
  67.  
  68. rop.insert(rop.mutable_begin(),temp2);
  69. rop2.insert(rop2.mutable_end(),temp);
  70. }
  71. else if(type==2){
  72. int x,y;
  73. cin>>x>>y;
  74. if(x>y)swap(x,y);
  75. if(x==0 && y==s.length()-1)continue;
  76. auto temp = rop.substr(x,y-x+1);
  77. rop.erase(x,y-x+1);
  78.  
  79. x = s.length()-x-1;
  80. y = s.length()-y-1;
  81. if(x<y)swap(x,y);
  82. auto temp2 = rop2.substr(y,x-y+1);
  83. rop2.erase(y,x-y+1);
  84.  
  85. rop.insert(rop.mutable_end(),temp2);
  86. rop2.insert(rop2.mutable_begin(),temp);
  87. }
  88. else{
  89. int y;
  90. cin>>y;
  91. cout<<rop[y]<<"\n";
  92. }
  93. }
  94. }
  95.  
Success #stdin #stdout 0s 4312KB
stdin
Standard input is empty
stdout
Standard output is empty