Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct tree
- {
- int val, cnt, set, lb, rb;
- tree()
- {
- val = 0;
- cnt = 0;
- lb = 0;
- rb = 0;
- set = -1;
- };
- };
- const int Q = (int)4e6 + 7;
- tree t[Q];
- int l, r, col;
- void push(int v, int tl, int tr)
- {
- if (t[v].set != -1)
- {
- t[v].val = t[v].set * (tr - tl + 1);
- t[v].lb = t[v].set;
- t[v].rb = t[v].set;
- t[v].cnt = t[v].set;
- if (tl != tr)
- {
- t[2 * v + 1].set = t[v].set;
- t[2 * v + 2].set = t[v].set;
- }
- t[v].set = -1;
- }
- }
- void update(int v, int tl, int tr)
- {
- push(v, tl, tr);
- if (l <= tl && tr <= r)
- {
- t[v].set = col;
- push(v, tl, tr);
- return;
- }
- int tm = tl + tr >> 1;
- if (!(tl > r || tm < l))
- update(2 * v + 1, tl, tm);
- else
- push(2 * v + 1, tl, tm);
- if (!((tm + 1) > r || tr < l))
- update(2 * v + 2, tm + 1, tr);
- else
- push(2 * v + 2, tm + 1, tr);
- t[v].val = t[2 * v + 1].val + t[2 * v + 2].val;
- t[v].cnt = t[2 * v + 1].cnt + t[2 * v + 2].cnt;
- if (t[2 * v + 1].rb == t[2 * v + 2].lb && t[2 * v + 2].lb == 1)
- --t[v].cnt;
- t[v].lb = t[2 * v + 1].lb;
- t[v].rb = t[2 * v + 2].rb;
- }
- int n;
- int solve()
- {
- scanf("%d", &n);
- forn(i, n)
- {
- char cl;
- int len;
- scanf(" %c %d %d", &cl, &l, &len);
- r = l + len - 1;
- col = (cl == 'B');
- update(0, -500000, 500000);
- printf("%d %d\n", t[0].cnt, t[0].val);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement