Draft saved on this device
▤ Description
ConcurrencyEasy
Count Active Threads From Start And Join Events
Replay a sequential trace of thread lifecycle events.
Replay a sequential trace of thread lifecycle events. START id inserts a newly started thread; JOIN id removes an active thread after it has been joined. The trace is valid: no thread ID is started twice without joining, and all joins refer to active threads. Count active threads after the final event.
Input format
First line N; next N lines START id or JOIN id.
Output format
Print the count of active threads.
Examples
Example 1
Input
5 START 1 START 2 JOIN 1 START 3 JOIN 2
Expected output
1
Constraints
- 0 ≤ N ≤ 100000
- 1 ≤ id ≤ 10^9
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.
⌘ Code
Loading Monaco C++ editor…
Checking judge...
Checking whether the external C++ judge is available.
⌁ Test cases & resultsPublic samples: 1
Input
5 START 1 START 2 JOIN 1 START 3 JOIN 2
Expected output
1