Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void push(vector<int>& t, int v) {
- if (t[v] != -1) {
- t[v * 2 + 1] = t[v];
- t[v * 2 + 2] = t[v];
- t[v] = -1;
- }
- }
- void build(vector<int>& a, vector<int>& t, int v, int tl, int tr) {
- if (tl == tr)
- t[v] = a[tl];
- else {
- int tm = (tl + tr) / 2;
- build(a, t, v * 2 + 1, tl, tm);
- build(a, t, v * 2 + 2, tm + 1, tr);
- }
- }
- void update(vector<int> &t, int v, int tl, int tr, int l, int r, int color) {
- if (l > r)
- return;
- if (l == tl && r == tr)
- t[v] = color;
- else {
- push(t, v);
- int tm = (tl + tr) / 2;
- update(t, v * 2 + 1, tl, tm, l, min(tm, r), color);
- update(t, v * 2 + 2, tm + 1, tr, max(tm + 1, l), r, color);
- }
- }
- int get(vector<int>& t, int v, int tl, int tr, int pos) {
- if (tl == tr)
- return t[v];
- push(t, v);
- int tm = (tl + tr) / 2;
- if (pos <= tm)
- return get(t, v * 2 + 1, tl, tm, pos);
- else
- return get(t, v * 2 + 2, tm + 1, tr, pos);
- }
Advertisement
Add Comment
Please, Sign In to add comment