cswork / OA打开练习工作台

Goldman SachsOA #27

Product of the Maximum and Minimum in a Dataset

估计中等可在线判题

考点(AI 标注)单调栈与堆哈希计数

Starting from an empty multiset, process the operations in order: push x inserts one x; pop x removes a single copy of an x that is currently present. After each operation, output the product of the current minimum and maximum of the set; if the set is empty, output 0, consistent with all three implementations in the fixed source (Python, Java, C++).

输入格式

The first line contains the number of operations n, followed by n lines, each push x or pop x. Complete original constraints: 1≤n≤100000, 1≤x≤10^9; whenever a pop is executed, the current multiset contains at least one x. The ranges of the fixed complete raw are kept; the standard input/output is this site's wrapper.

输出格式

On each line, output the product after the corresponding operation; output 0 when the multiset is empty. Compute the product as a 64-bit integer.

样例 1

输入:

4
push 1
push 2
push 3
pop 1

输出:

1
2
3
6

样例说明

Duplicate values are handled as a multiset, and pop removes only one copy; this behavior matches the reference implementations in the three languages of the fixed source.