cswork / OA打开练习工作台

Pure StorageOA #6

Lock Acquire/Release Log Checker

估计简单可在线判题

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

Each event is ACQUIRE lock or RELEASE lock. Locks must be released in the reverse order of acquisition; a lock that is already held cannot be acquired again, and a lock that is not held cannot be released. Return the 1-based index of the first erroneous event; if no event is erroneous but some lock is still held at the end, return the number of events + 1; otherwise return 0.

输入格式

The first line contains n; each of the next n lines is ACQUIRE name or RELEASE name. Added by this site: 0≤n≤200000, and name is an ASCII identifier without whitespace.

输出格式

Output the index of the first error, n+1 in the dangling case, or 0.

样例 1

输入:

4
ACQUIRE A
ACQUIRE B
RELEASE B
RELEASE A

输出:

0

样例 2

输入:

2
ACQUIRE A
RELEASE B

输出:

2

样例 3

输入:

3
ACQUIRE A
ACQUIRE B
RELEASE A

输出:

3