cswork / OA打开练习工作台

DatabricksOA #4

Triples with Common Difference (Dynamic Multiset)

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

考点(AI 标注)哈希计数

Given an empty array that should contain integer numbers, your task is to process a list of queries on it. Specifically, there are two types of queries:

  • "+x" — append x to numbers. numbers may contain multiple instances of the same number.
  • "-x" — remove all the instances of x from numbers.

After processing each query, count the number of triples (x, y, z) in numbers which meet this condition: both x - y and y - z are equal to a given diff. The final output should be an array of counts after each query.

Example: queries=["+4","+5","+6","+4","+3","-4"], diff=1 returns [0, 0, 1, 2, 4, 0].

Constraints

values in [-10⁹, 10⁹]; at most 10⁵ queries.