Design a structure that supports adding points and counting squares. Points are integer coordinates [x, y].
count(point) returns the number of axis-aligned squares that can be formed with point as one corner and previously added points as the other corners.
Axis-aligned means the square sides are parallel to the x-axis and y-axis. Duplicate points count as separate points, so frequencies matter.
Examples
Input: operations = ["DetectSquares","add","add","add","count","count"], points = [[],[3,10],[11,2],[3,2],[11,10],[14,8]] Output: [null,null,null,null,1,0]
Input: operations = ["DetectSquares","add","add","add","add","count"], points = [[],[5,5],[5,7],[7,5],[7,7],[5,5]] Output: [null,null,null,null,null,1]
Constraints
- 1 <= operations.length <= 3,000
- operations[i] is one of DetectSquares, add, or count.
- 0 <= x, y <= 1,000