fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  6.  
  7. #include <ext/pb_ds/assoc_container.hpp>
  8. #include <ext/pb_ds/tree_policy.hpp>
  9. using namespace __gnu_pbds;
  10.  
  11. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>order_set;
  12. typedef pair<int, int>pr;
  13. #define all(i) i.begin() , i.end()
  14. #define ft first
  15. #define sn second
  16. #define pb push_back
  17.  
  18. #define totalone(mask) __builtin_popcount(mask)
  19. #define chkbit(mask,bit) (mask&(1LL << bit))
  20. #define setbit(mask,bit) (mask|(1LL << bit))
  21. #define cngbit(mask,bit) (mask^(1LL << bit))
  22.  
  23. #define en "\n"
  24. #define dbg(x) cerr<<#x<<" is : "<<x<<en;
  25. #define here cout<<"rony\n"
  26. #define yes cout<<"YES\n";
  27. #define no cout<<"NO\n";
  28. #define report cout<<-1<<en;
  29. #define sum(n) ((1LL*(n)*(n+1))/ 2LL)
  30. #define sqr(n) (1LL*(n)*(n))
  31. #define vag(a,b) ((a + b - 1)/b)
  32. #define coutv(v) for(auto i: v) cout<<i<<" ";cout<<en;
  33. #define cinv(v) for(auto &i: v) cin >> i;
  34.  
  35. #define MAXN 100001
  36. #define inf 1e6+5
  37. const int mod = 1e9 + 7;
  38.  
  39. vector<int>g[MAXN];
  40. int vis[MAXN];
  41.  
  42. struct segment_tree
  43. {
  44. struct NODE {
  45. int st , EN, value;// start , end
  46.  
  47. void init(int L, int R) {
  48. st = L, EN = R;
  49. value = 0;
  50. }
  51. } g[4 * MAXN];
  52.  
  53. void build(int CN, int L, int R)
  54. {
  55. g[CN].init(L, R);
  56.  
  57. if (L == R ) return;
  58. int mid = (L + R) >> 1;
  59. int LN = CN << 1;
  60.  
  61. build(LN, L, mid);
  62. build(LN | 1, mid + 1, R);
  63. }
  64.  
  65. void update(int CN, int l, int r)
  66. {
  67. int x = g[CN].st;
  68. int y = g[CN].EN;
  69. if (y < l || x > r) return;
  70.  
  71. if (l <= x && r >= y ) {
  72. g[CN].value += 1;
  73. // dbg(x);
  74. return;
  75. }
  76.  
  77. update(CN * 2, l, r);
  78. update(CN * 2 + 1, l, r);
  79. }
  80.  
  81. int query(int CN, int id, int carry)
  82. {
  83. int x = g[CN].st;
  84. int y = g[CN].EN;
  85. if (y < id || x > id) return 0;
  86.  
  87. if (id <= x && id >= y ) {
  88. return g[CN].value + carry;
  89. }
  90.  
  91. int ans = query(CN * 2, id, carry + g[CN].value);
  92. ans += query(CN * 2 + 1, id, carry + g[CN].value);
  93. return ans;
  94. }
  95.  
  96. } s_tree;
  97. void solve()
  98. {
  99. string s;
  100. cin >> s;
  101. int q;
  102. cin >> q;
  103.  
  104. int n = s.size();
  105. s_tree.build(1, 1, n);
  106.  
  107. while (q--)
  108. {
  109. char c; int x, y;
  110. cin >> c;
  111. if (c == 'I') {
  112. cin >> x >> y;
  113. s_tree.update(1, x, y);
  114. }
  115. else {
  116. cin >> x;
  117. int an = s_tree.query(1, x, 0) % 2;
  118. if (an) cout << (s[x - 1] == '0' ? '1' : '0') << en;
  119. else cout << s[x - 1] << en;
  120.  
  121. }
  122. }
  123. }
  124. int main()
  125. {
  126. IOS;
  127. ll t;
  128. t = 1;
  129. cin >> t;
  130. int c = 0;
  131. while ( t-- )
  132. {
  133. cout << "Case " << ++c << ":\n";
  134. solve();
  135. }
  136. return 0;
  137. }
Runtime error #stdin #stdout 0.01s 5720KB
stdin
Standard input is empty
stdout
Standard output is empty