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:

After adding the points, the first count query finds 1 square and the later count query also finds 1 square, so the result is [null,null,null,null,null,1,null,null,null,1].

Constraints

  • 0 ≤ x, y ≤ 1000

Ready to solve this problem?

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