Track Move-Only Resource Ownership
Simulate ownership transfers of non-copyable C++ resources.
There are N named resource handles, indexed 1..N; initially none own a resource. CREATE i assigns a new resource to handle i. MOVE a b moves ownership FROM handle b TO handle a, leaving b empty; the previous resource of a is released. RESET i releases any resource owned by i. Print the number of handles that own a resource after processing all commands. Model valid move-only ownership rules.
Input format
First line: N Q. Next Q lines: CREATE i, MOVE a b, or RESET i.
Output format
Print the count of nonempty handles after the final command.
Examples
3 5 CREATE 1 CREATE 2 MOVE 3 1 RESET 2 CREATE 1
2
Handles 1 and 3 own resources.
Constraints
- 1 ≤ N ≤ 100000
- 1 ≤ Q ≤ 100000
- 1 ≤ a,b,i ≤ N
- For MOVE a b, a ≠ b.
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.
3 5 CREATE 1 CREATE 2 MOVE 3 1 RESET 2 CREATE 1
2