cswork / OAOpen practice workspace

Applied IntuitionOA #2

KV Store with Nested Transactions

Estimated MediumJudge-ready

Topics (AI-labelled)IteratorsStacks & Heaps

Implement SET/GET/DELETE and nested BEGIN/ROLLBACK/COMMIT; GET on a missing key gives NULL; committing or rolling back with no transaction outputs NO TRANSACTION.

See "Input" for the standard I/O conventions and constraints added by this site.

Input

q≤200000 lines; keys and values contain no spaces.

Output

Output the GET results and the no-transaction errors.

Example 1

Input:

6
SET x 1
BEGIN
SET x 2
GET x
ROLLBACK
GET x

Output:

2
1

Example 2

Input:

3
GET miss
COMMIT
ROLLBACK

Output:

NULL
NO TRANSACTION
NO TRANSACTION

Example 3

Input:

9
SET a z
BEGIN
DELETE a
BEGIN
SET b y
COMMIT
GET b
ROLLBACK
GET a

Output:

y
z

Editorial

Loading solution…