Description

Design a data structure to detect axis-aligned squares formed by added points. Return count of ways to form a square with a given query point.

Examples

Input:operations = [["add",[3,10]],["add",[11,2]],["add",[3,2]],["count",[11,10]],["count",[14,8]]]
Output:[null,null,null,1,0]
Explanation:

One square with point [11,10].

Input:operations = [[1]],["add",[11,2]],["add",[3,2]],["count",[11,10]],["count",[14,8]]]
Output:[1]
Explanation:

Minimal case with a single operation.

Input:["DetectSquares",[],"add",[0,0],"add",[5,0],"add",[0,5],"add",[5,5],"count",[0,0],"add",[2,3],"add",[6,7],"add",[2,7],"count",[6,3]]
Output:[null,null,null,null,null,1,null,null,null,1]
Explanation:

First adding points (0,0), (5,0), (0,5), (5,5) which form a square with side length 5. When counting from (0,0), searching finds 1 square. Then adding points (2,3), (6,7), (2,7) and count from (6,3) - these four points form another square with side length 4, so this gives 1 square.

Constraints

  • 0 ≤ x, y ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!