public int Propagate(SegmentTree subRoot) { if (subRoot != null) { subRoot.val++; int l = Propagate(subRoot.left); int r = Propagate(subRoot.right); return(Math.Max(subRoot.val, Math.Max(l, r))); } else { return(0); } }
public int UpdateRange(int start, int end) { if (start == leftValue && end == rightValue) { int ret = Propagate(this); return(Math.Max(ret, val)); } int mid = (leftValue + rightValue) / 2; if (end <= mid) { if (left == null) { this.left = new SegmentTree(val, leftValue, mid); } return(Math.Max(val, this.left.UpdateRange(start, end))); } else if (start <= mid && mid < end) { if (left == null) { this.left = new SegmentTree(val, leftValue, mid); } if (right == null) { this.right = new SegmentTree(val, mid + 1, rightValue); } var ret = Math.Max(this.left.UpdateRange(start, mid), this.right.UpdateRange(mid + 1, end)); return(Math.Max(val, ret)); } else { if (right == null) { this.right = new SegmentTree(val, mid + 1, rightValue); } return(Math.Max(val, this.right.UpdateRange(start, end))); } }
public MyCalendarThree() { st = new SegmentTree(0, 0, 119); }