Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct SegmentTree {
- int n;
- vector<int> v;
- vector<int> st;
- SegmentTree(vector<int> &v) : v(v) {
- int n = v.size();
- st.resize(4*n);
- build(0, 0, n);
- }
- }
- int SegmentTree::build(int idx, int l, int r) {
- if (l == r) { return st[idx] = v[l]; }
- int lc = 2 * idx + 1;
- int rc = 2 * idx + 2;
- int m = (l + r) / 2;
- return st[idx] = min(build(lc, l, m), build(rc, m+1, r));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement