Staged Config Changes
Your deployment tool keeps a store of feature flags. Each flag has a name and an integer value (a rollout percentage, a timeout, a version number). Operators don't edit the live store blindly: they open a change set, make edits, look at the result, and then either publish it or throw it away. Change sets can be nested, so a cautious operator can try something inside a change set that is itself still being tried.
Implement the store. It starts empty, with no change set open, and processes these commands:
SET k v: flagknow has valuev(it is created if it does not exist).UNSET k: flagkno longer exists. Nothing happens if it does not exist.GET k: print the value of flagk, orNULLif it does not exist.COUNT v: print how many flags currently have valuev.BEGIN: open a new change set, nested inside the currently open ones.ROLLBACK: close the innermost open change set and undo everySETandUNSETmade since it was opened (including those made inside change sets nested in it that were committed into it). Every flag returns to exactly the state it had when thatBEGINran.COMMIT: close the innermost open change set and keep its edits. If an enclosing change set is still open, the edits now belong to it, so rolling that one back later undoes them too. If no change set remains open, the edits are final.
If ROLLBACK or COMMIT is issued while no change set is open, print NO CHANGE SET and change
nothing.
GET and COUNT always see the current state, including the edits of all open change sets.
Input
The first line contains q (1 ≤ q ≤ 2·10^5), the number of commands. Each of the next q lines
contains one command in the format above.
Flag names k consist of 1 to 10 lowercase English letters and digits. Values v are integers with
−10^9 ≤ v ≤ 10^9. At least one command is a GET or a COUNT. Change sets still open after the
last command are simply left open.
Output
For every GET and COUNT, and for every ROLLBACK or COMMIT issued with no change set open,
print one line with the result, in the order of the commands.
Notes
In the first example the inner rollback brings search back with value 50, and the outer one
restores checkout to 50.
In the second example the first COMMIT has nothing to close. The second COMMIT merges the inner
change set into the outer one, so the following ROLLBACK undoes the edits of both: beta and
gamma are gone again. The last ROLLBACK has nothing to close.