static long Next(long x0)
        {
            Treap first, second;

            treap.Split(x0 - 1, out first, out second);

            long ans = -1;

            if (second != null)
            {
                ans = second.min;
            }
            return(ans);
        }
예제 #2
0
        public void Split(int x0, out Treap first, out Treap second)
        {
            Treap newTreap = null;

            if (x <= x0)
            {
                if (right == null)
                {
                    second = null;
                }
                else
                {
                    right.Split(x0, out newTreap, out second);
                }
                first = new Treap(x, y, left, newTreap);
            }
            else
            {
                if (left == null)
                {
                    first = null;
                }
                else
                {
                    left.Split(x0, out first, out newTreap);
                }
                second = new Treap(x, y, newTreap, right);
            }
        }
        public void Split(long x, out Treap L, out Treap R)
        {
            Treap newTree = null;

            if (this.x <= x)
            {
                if (Right == null)
                {
                    R = null;
                }
                else
                {
                    Right.Split(x, out newTree, out R);
                }
                L = new Treap(this.x, y, Left, newTree);
            }
            else
            {
                if (Left == null)
                {
                    L = null;
                }
                else
                {
                    Left.Split(x, out L, out newTree);
                }
                R = new Treap(this.x, y, newTree, Right);
            }
        }