Count Points in Inclusive Circular Queries. Each entry of points gives integer x and y coordinates; repeated coordinates count as separate points. Each query [x,y,r] asks how many points lie inside or on the circle centered at (x,y) with radius r.
### Problem
Each entry of `points` gives integer x and y coordinates; repeated coordinates count as separate points. Each query `[x,y,r]` asks how many points lie inside or on the circle centered at (x,y) with radius r. Return counts in query order.
```cpp
class Solution {
public:
vector<int> countPoints(vector<vector<int>>& points, vector<vector<int>>& queries);
};
```
### Examples
**Example 1:**
```text
points = [[0,0],[3,4],[3,4]], queries = [[0,0,5],[3,4,1]]
Output: [3,2]
Explanation: The duplicate points on the first circle’s boundary both count.
```
**Example 2:**
```text
points = [[1,1],[2,2],[4,4]], queries = [[2,2,1],[0,0,2]]
Output: [1,1]
Explanation: The first query includes only [2,2]; the second includes only [1,1].
```
### Constraints
- There are `1..500` points, each with two integer coordinates in `[0,500]`.
- There are `1..500` queries, each with three integers.
- Query centers have coordinates in `[0,500]` and radii in `[1,500]`.
### Clarifying Questions
The circle border is included. Duplicate coordinates are not deduplicated, and query ordering must be preserved.
```hint Inspect the structure
How should a point on the circular boundary be treated, and do repeated coordinates count separately?
```
### Reasoning checkpoints
- Treat points exactly on each circular boundary as inside.
- Count each point occurrence separately.
- Discuss the source follow-up about better than linear work per query.
### Optional extensions
The source follow-up asks for better than `O(P)` time per query for `P` points. For the fixed point set and the stated integer bounds, give an exact method that meets this goal after preprocessing. State its preprocessing time, storage, and worst-case query time. If you also discuss a spatial index, explain when it prunes work and whether it guarantees the requested bound.
Overview: Count Points in Inclusive Circular Queries. Each entry of points gives integer x and y coordinates; repeated coordinates count as separate points. Each query [x,y,r] asks how many points lie inside or on the circle centered at (x,y) with radius r.
Each entry of points gives integer x and y coordinates; repeated coordinates count as separate points. Each query [x,y,r] asks how many points lie inside or on the circle centered at (x,y) with radius r. Return counts in query order.
class Solution {
public:
vector<int> countPoints(vector<vector<int>>& points, vector<vector<int>>& queries);
};
Examples
Example 1:
points = [[0,0],[3,4],[3,4]], queries = [[0,0,5],[3,4,1]]
Output: [3,2]
Explanation: The duplicate points on the first circle’s boundary both count.
Example 2:
points = [[1,1],[2,2],[4,4]], queries = [[2,2,1],[0,0,2]]
Output: [1,1]
Explanation: The first query includes only [2,2]; the second includes only [1,1].
Constraints
There are
1..500
points, each with two integer coordinates in
[0,500]
.
There are
1..500
queries, each with three integers.
Query centers have coordinates in
[0,500]
and radii in
[1,500]
.
Clarifying Questions Guidance
The circle border is included. Duplicate coordinates are not deduplicated, and query ordering must be preserved.
Reasoning checkpoints
Treat points exactly on each circular boundary as inside.
Count each point occurrence separately.
Discuss the source follow-up about better than linear work per query.
Optional extensions
The source follow-up asks for better than O(P) time per query for P points. For the fixed point set and the stated integer bounds, give an exact method that meets this goal after preprocessing. State its preprocessing time, storage, and worst-case query time. If you also discuss a spatial index, explain when it prunes work and whether it guarantees the requested bound.