Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. struct SegmentTree {
  2. int n;
  3. vector<int> v;
  4. vector<int> st;
  5.  
  6. SegmentTree(vector<int> &v) : v(v) {
  7. int n = v.size();
  8. st.resize(4*n);
  9. build(0, 0, n);
  10. }
  11. }
  12.  
  13. int SegmentTree::build(int idx, int l, int r) {
  14. if (l == r) { return st[idx] = v[l]; }
  15.  
  16. int lc = 2 * idx + 1;
  17. int rc = 2 * idx + 2;
  18. int m = (l + r) / 2;
  19.  
  20. return st[idx] = min(build(lc, l, m), build(rc, m+1, r));
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement