题目是Mario bought n math books and he recorded their prices. The prices are all integers, and the price sequence is a = {a0, a2, ...ai , ..., an−1} of length n (n ≤ 100000). Please help him to manage this price
sequence. There are three types of operations:
• BUY x: buy a new book with price x, thus x is added at the end of a.
• CLOSEST ADJ PRICE: output the minimum absolute difference between adjacent prices.
• CLOSEST PRICE: output the absolute difference between the two closest prices in the entire sequence.
A total of m operations are performed (1 ≤ m ≤ 100000). Each operation is one of the three mentioned types. You need to write a program to perform given operations. For operations ”CLOSEST ADJ PRICE” and ”CLOSEST PRICE” you need to output the corresponding answers.
2.2 Input
The first line contains two integers n and m, representing the length of the original sequence and the number of operations.
The second line consists of n integers, representing the initial sequence a. Following that are m lines, each containing one operation: either BUY x, CLOSEST ADJ PRICE, or CLOSEST PRICE (without extra spaces or empty lines).
2.3 Output
For each CLOSEST ADJ PRICE and CLOSEST PRICE command, output one line as the answer.答案是class Node:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None


class BST:
    def __init__(self):
        self.root = None

    def insert(self, value):
        if self.root is None:
            self.root = Node(value)
        else:
            self._insert(value, self.root)

    def _insert(self, value, node):
        if value < node.data:
            if node.left is None:
                node.left = Node(value)
            else:
                self._insert(value, node.left)
        elif value > node.data:
            if node.right is None:
                node.right = Node(value)
            else:
                self._insert(value, node.right)

    def predecessor(self, value):
        predecessor = None
        current = self.root
        while current:
            if current.data < value:
                predecessor = current
                current = current.right
            elif current.data > value:
                current = current.left
            else:
                return value
        return predecessor.data if predecessor else float('-inf')

    def successor(self, value):
        successor = None
        current = self.root
        while current:
            if current.data > value:
                successor = current
                current = current.left
            else:
                current = current.right
        return successor.data if successor else float('inf')


n, m = map(int, input().split())
prices = []
pricesTree = BST()
adjacentDifferences = float('inf')

price = list(map(int, input().split()))
for _ in range(n):
    p = price[_]
    pricesTree.insert(p)
    prices.append(p)
    if len(prices) > 1:
        diff = abs(p - prices[-2])
        if diff < adjacentDifferences:
            adjacentDifferences = diff

differences = adjacentDifferences

temp = sorted(prices)
for i in range(1, len(temp)):
    diff = abs(temp[i] - temp[i - 1])
    if diff < differences:
        differences = diff

for _ in range(m):
    operation = input().split()
    if operation[0] == 'BUY':
        x = int(operation[1])
        lastPrice = prices[-1]
        adjDiff = abs(x - lastPrice)
        if adjDiff < adjacentDifferences:
            adjacentDifferences = adjDiff
        prices.append(x)
        pred = pricesTree.predecessor(x)
        succ = pricesTree.successor(x)
        diff1 = abs(pred - x)
        diff2 = abs(x - succ)
        diff = min(diff1, diff2)
        if diff < differences:
            differences = diff
        pricesTree.insert(x)
    elif operation[0] == 'CLOSEST_ADJ_PRICE':
        print(adjacentDifferences)
    elif operation[0] == 'CLOSEST_PRICE':
        print(differences)     要求是write a report to explain the following:
• What are the possible solutions for the problem?
• How do you solve this problem?
• Why is your solution better than others?