コード例 #1
0
 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);
     }
 }
コード例 #2
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)));
            }
        }
コード例 #3
0
 public MyCalendarThree()
 {
     st = new SegmentTree(0, 0, 119);
 }