Draft saved on this device
▤ Description
ConcurrencyEasy
Simulate An Atomic Counter Increment Stream
Simulate a serialized log of operations on an integer counter, initially 0.
Simulate a serialized log of operations on an integer counter, initially 0. ADD x increases the counter by x; RESET sets it to 0. The word atomic describes the original producer's counter, but this task processes an already-ordered log.
Input format
First line N; next N lines ADD x or RESET.
Output format
Print the final signed counter value.
Examples
Example 1
Input
5 ADD 5 ADD -2 RESET ADD 7 ADD 1
Expected output
8
Constraints
- 0 ≤ N ≤ 100000
- -10^9 ≤ x ≤ 10^9
- The answer fits signed 64-bit.
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 ADD 5 ADD -2 RESET ADD 7 ADD 1
Expected output
8