Implement a Deterministic Observer Dispatcher
Process subscriptions and notifications in a stable registration order.
Build a reference event dispatcher. SUB id subscribes an observer if not already subscribed, placing it at the end. UNSUB id removes it if present. EMIT sends a notification to all currently subscribed observers in their registration order. Print IDs for each EMIT, space separated, or NONE if there are no subscribers. A re-subscribed observer is appended to the end.
Input format
First line: Q. Next Q lines: SUB id, UNSUB id, or EMIT.
Output format
One line per EMIT: observer IDs separated by spaces, or NONE.
Examples
7 SUB 2 SUB 1 EMIT UNSUB 2 SUB 2 EMIT EMIT
2 1 1 2 1 2
Constraints
- 1 ≤ Q ≤ 10000
- 1 ≤ id ≤ 100000
Related concepts
This early-access exercise uses standard input/output. More advanced concurrency challenges will use specialized class interfaces, instrumentation, and stress tests once the judging infrastructure is ready.
Loading Monaco C++ editor…
Checking whether the external C++ judge is available.
7 SUB 2 SUB 1 EMIT UNSUB 2 SUB 2 EMIT EMIT
2 1 1 2 1 2