Account
Draft saved on this device
▤ DescriptionOriginal CppValley problem
ConcurrencyEasy

Detect A Missing Thread Join In A Trace

Each thread ID appears in exactly one START event, and may have one JOIN event after it starts.

Each thread ID appears in exactly one START event, and may have one JOIN event after it starts. Determine how many started threads have not been joined when the trace ends. This evaluates a recorded event trace, not real synchronization.

Input format

First line N; next N lines START id or JOIN id.

Output format

Print the number of threads missing a JOIN.

Examples

Example 1
Input
4
START 1
START 2
JOIN 1
START 3
Expected output
2

Constraints

  • 0 ≤ N ≤ 100000
  • 1 ≤ id ≤ 10^9
  • Each JOIN corresponds to an earlier START.

Related concepts

Thread Lifecycle

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
4
START 1
START 2
JOIN 1
START 3
Expected output
2
Execution requires a secure external judge.