cswork / OA打开练习工作台

DatabricksOA #14

Count Triples with Difference

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)哈希计数

To view the original problem statement, pls check out the source image below Imagine you have an empty collection of numbers, and you're given a list of instructions to add or remove numbers from this collection. Your task is to follow these instructions carefully and, after each one, count how many special groups of three numbers (we call them "triples") can be made from the numbers in your collection. Here's how a triple works: you need to pick three numbers, let’s call them x, y, and z. For them to count as a triple, the difference between x and y must be the same as the difference between y and z. This means that if you rearrange the numbers correctly, they should form a nice pattern like x, y, z. For each instruction, you either add a new number to your collection or remove all instances of a specific number from it. After every single instruction, you have to check how many triples you can make with the current set of numbers. The story has a few rules to keep things interesting: The numbers involved are very large and can range from extremely negative to extremely positive. When you're asked to remove a number, you can be sure that the number is actually in the collection—no need to worry about trying to remove something that isn’t there. Finally, no matter how many triples you end up counting, the result will always be small enough to fit in a standard counting device. Your ultimate goal is to create a list of these counts after processing each instruction, showing how the number of possible triples changes as you add or remove numbers.