Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define endl '\n'
- #define sz(v) (int)v.size()
- #define all(v) v.begin(), v.end()
- void dbg_out() { cerr << "\b\b]\n"; }
- template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
- #define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)
- /****************************** CODE IS HERE ***********************************/
- //IT is prefer to use printf instead of cout, this mistake causes me 20+ runtime error
- struct BIT {
- vector <int> bit;
- int n;
- BIT (int _n) {
- n = _n;
- bit.assign(n+10, 0);
- }
- void upd(int i, bool val) {
- for (++i; i <= n; i += i&-i)
- bit[i] += val;
- }
- int qry(int i) {
- int res = 0;
- for (++i; i > 0; i-=i&-i)
- res += bit[i];
- return res % 2;
- }
- };
- void solve() {
- string s; cin >> s;
- int n = sz(s);
- BIT ft(n);
- int q; cin >> q;
- while (q--) {
- char type; cin >> type;
- if (type == 'I') {
- int l, r; cin >> l >> r;
- l--;
- ft.upd(l, 1);
- ft.upd(r, -1);
- }
- else {
- int pos; cin >> pos;
- pos--;
- int ans = (s[pos] == '1') ^ ft.qry(pos);
- printf("%d\n", ans);
- //cout << ans << endl;
- }
- }
- }
- int main(){
- ios_base::sync_with_stdio(false); cin.tie(nullptr);
- int t; cin >> t;
- for (int i = 1; i <= t; ++i) {
- printf("Case %d:\n", i);
- solve();
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment