← 返回 databricks 的题目列表IP CIDR Range Query
类型:online_judge
Problem: IP CIDR Range Query
Given a list of IPv4 CIDR ranges and a list of query IP addresses, implement a program to determine whether each query IP belongs to at least one of the given CIDR ranges.
An IPv4 address has the format a.b.c.d, where each part is an integer from 0 to 255. A CIDR range has the format ip/prefixLen, for example 192.168.1.0/24, which represents all IPv4 addresses sharing the same first 24 bits.
Input Format
n
cidr_1
cidr_2
...
cidr_n
q
ip_1
ip_2
...
ip_q
n: number of CIDR ranges
The next n lines: one CIDR string per line
q: number of queries
The next q lines: one IPv4 address per line
Output Format
For each query IP, print one line:
YES if the IP belongs to at least one CIDR range
NO otherwise
Constraints
1 <= n <= 2 * 10^5
1 <= q <= 2 * 10^5
All IP addresses are valid IPv4 addresses
0 <= prefixLen <= 32
Example
Input:
3
192.168.1.0/24
10.0.0.0/8
172.16.5.10/32
5
192.168.1.42
192.168.2.1
10.2.3.4
172.16.5.10
172.16.5.11
Output:
YES
NO
YES
YES
NO
Example
Input
3
192.168.1.0/24
10.0.0.0/8
172.16.5.10/32
5
192.168.1.42
192.168.2.1
10.2.3.4
172.16.5.10
172.16.5.11
Output
YES
NO
YES
YES
NO