Guest User

Untitled

a guest
Jun 15th, 2020
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define endl '\n'
  5. #define sz(v) (int)v.size()
  6. #define all(v) v.begin(), v.end()
  7. void dbg_out() { cerr << "\b\b]\n"; }
  8. template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
  9. #define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)
  10.  
  11.  
  12. /****************************** CODE IS HERE ***********************************/
  13.  
  14. //IT is prefer to use printf instead of cout, this mistake causes me 20+ runtime error
  15.  
  16. struct BIT {
  17.     vector <int> bit;
  18.     int n;
  19.     BIT (int _n) {
  20.         n = _n;
  21.         bit.assign(n+10, 0);
  22.     }
  23.     void upd(int i, bool val) {
  24.         for (++i; i <= n; i += i&-i)
  25.             bit[i] += val;
  26.     }
  27.  
  28.     int qry(int i) {
  29.         int res = 0;
  30.         for (++i; i > 0; i-=i&-i)
  31.             res += bit[i];
  32.      
  33.         return res % 2;
  34.     }
  35.    
  36. };
  37.  
  38.  
  39. void solve() {
  40.     string s; cin >> s;
  41.     int n = sz(s);
  42.  
  43.     BIT ft(n);
  44.  
  45.     int q; cin >> q;
  46.     while (q--) {
  47.         char type; cin >> type;
  48.         if (type == 'I') {
  49.             int l, r; cin >> l >> r;
  50.             l--;
  51.             ft.upd(l, 1);
  52.             ft.upd(r, -1);
  53.        
  54.         }
  55.         else {
  56.             int pos; cin >> pos;
  57.             pos--;
  58.             int ans = (s[pos] == '1') ^ ft.qry(pos);
  59.             printf("%d\n", ans);
  60.             //cout << ans << endl;
  61.         }
  62.     }
  63.  
  64. }
  65.  
  66. int main(){
  67.     ios_base::sync_with_stdio(false); cin.tie(nullptr);
  68.     int t; cin >> t;
  69.  
  70.     for (int i = 1; i <= t; ++i) {
  71.         printf("Case %d:\n", i);
  72.         solve();
  73.     }
  74.  
  75.  
  76.     return 0;
  77. }
Add Comment
Please, Sign In to add comment