You are given a sequence of operations applied to an initially empty multiset of integers. Each operation is either +x, which inserts one additional copy of x, or -x, which removes every copy of x currently in the multiset. If x is absent, a removal operation makes no change, but a count must still be produced.
After each operation, compute how many triples of element occurrences (a, b, c) from the current multiset satisfy and . Equivalently, the multiset values involved are consecutive terms of an arithmetic progression with common difference diff.
If the current multiset contains copies of , copies of , and copies of , then these copies form distinct triples whose largest value is . The returned list should have one count for each operation, in the order the operations were processed.
Implement count_triples_after_each(operations: list[str], diff: int) -> list[int].
Example 1:
Input: operations = ["+2","+5","+8","+5","+2","-5"], diff = 3
Output: [0,0,1,2,4,0]
Explanation: The values 2, 5, and 8 first form a progression after "+8". The later "+5" and "+2" increase the count to 2 and then 4. Removing all copies of 5 with "-5" leaves no progression.
operations = ["+2","+5", "+8", "+5", "+2", "-5"] diff = 3
[0,0, 1, 2, 4, 0]
empty
Start with an empty multiset. diff = 3, so we look for values a, a-3, a-6.
Example 2:
Input: operations = ["+3","+7","+11","+3","+7","-20","+11"], diff = 4
Output: [0,0,1,2,4,4,8]
Explanation: The progression is 3, 7, 11. Adding more copies of 3 and 7 raises the count to 2 and 4. "-20" has no effect because 20 is absent, so the count remains 4. The final "+11" makes the occurrence counts of 3, 7, and 11 equal to 2, 2, and 2, producing 8 triples.
Example 3:
Input: operations = ["+0","+5","+10","-0"], diff = 5
Output: [0,0,1,0]
Explanation: After "+10", the three values 0, 5, and 10 form one progression. Removing all copies of 0 with "-0" eliminates it.
Constraints:
+ or - followed immediately by the digits of an integer x, with and no leading zeros except for itself.long in Java or long long in C++. Every returned count is at most .operations = ["+2","+5", "+8", "+5", "+2", "-5"] diff = 3
[0,0, 1, 2, 4, 0]
empty
Start with an empty multiset. diff = 3, so we look for values a, a-3, a-6.