Account
Draft saved on this device
▤ DescriptionOriginal CppValley problem
Design PatternsMedium

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

Example 1
Input
7
SUB 2
SUB 1
EMIT
UNSUB 2
SUB 2
EMIT
EMIT
Expected output
2 1
1 2
1 2

Constraints

  • 1 ≤ Q ≤ 10000
  • 1 ≤ id ≤ 100000

Related concepts

ObserverEvent-DrivenState Machines

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.

⌘ CodeC++17
GNU C++17 · main.cpp

Loading Monaco C++ editor…

Checking judge...

Checking whether the external C++ judge is available.

⌁ Test cases & resultsPublic samples: 1
Input
7
SUB 2
SUB 1
EMIT
UNSUB 2
SUB 2
EMIT
EMIT
Expected output
2 1
1 2
1 2
Execution requires a secure external judge.