← 返回 cisco 的题目列表Stock Price Fluctuation
类型:online_judge
Problem: Stock Price Fluctuation
Design a data structure to record the price of a stock at different timestamps and support queries for the current price, maximum price, and minimum price.
Implement the StockPrice class:
StockPrice() initializes the object.
void update(int timestamp, int price): records the stock price at timestamp as price.
If there is already a price recorded at this timestamp, this operation updates/corrects the previous price.
int current(): returns the stock price at the latest timestamp.
int maximum(): returns the maximum stock price among all currently valid timestamp records.
int minimum(): returns the minimum stock price among all currently valid timestamp records.
Input Format
For online judging, use the following format:
The first line contains an integer n, the number of operations.
The next n lines each contain one operation:
update timestamp price
current
maximum
minimum
For each query operation, print one line containing the answer.
Constraints
1 <= timestamp, price <= 10^9
1 <= n <= 10^5
current, maximum, and minimum are only called after at least one update.
Example
Input
7
update 1 10
update 2 5
current
maximum
update 1 3
maximum
minimum
Output
5
10
5
3