I. 2023冬-A-2 PeekMax in Stack

    传统题 150ms 64MiB

2023冬-A-2 PeekMax in Stack

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

题目描述

A stack is a First-In-Last-Out linear structure. Here you are supposed to implement a special function that allows you to find the maximum key value (PeekMax) in a stack, besides the normal Push and Pop. The point is, this new function must not slow down the overall performance of this stack.

输入格式

Each input file contains one test case. For each case, the first line gives a positive integer nn (105\le 10^5), which is the number of operations. Then nn lines follow, each gives an operation in the format:

  • Push X, means to push element X onto the stack, where X is an integer of which the absolute value is no more than 2302^{30};
  • Pop means to pop the top element out of the stack;
  • PeekMax means to return the maximum value of the keys in the current stack.

输出格式

For each operation, execute as it is defined. For each Pop, print in a lien the key value of the popped element; and for each PeekMax, print in a line the maximum value of the keys in the current stack. If the stack is empty when Pop or PeekMax is called, output ERROR instead. It is guaranteed that there is at least one line of output.

样例

11
Pop
Push 34
Push 28
PeekMax
Push 84
PeekMax
Pop
PeekMax
Pop
Pop
PeekMax
ERROR
34
84
84
34
28
34
ERROR

限制

Java (javac) 时间限制 650 ms 内存限制 256 MB

Python (python3) 时间限制 250 ms 内存限制 64 MB

其他编译器 时间限制 150 ms 内存限制 64 MB

PAT2023冬季重现赛

未参加
状态
已结束
规则
IOI
题目
11
开始于
2025-8-24 14:00
结束于
2025-8-24 17:30
持续时间
3.5 小时
主持人
参赛人数
32