#P9279. [AGM 2023 资格赛] IPs
[AGM 2023 资格赛] IPs
Background
Mike has just found an internship at the DNS department of a local Internet Service Provider. They know Mike is familiar with IPs, so they asked him to implement a management system for their customers that supports some operations. Some operations are client-specific, while others are specific to the DNS (the company). Mike is actually not very familiar with IPs, so he asks you for help.
Problem Description
The value range of IPs is from to , and initially all clients can use all IPs. There are countries (indexed from to ). Each country has its own IP set, which can be formally represented as the union of several intervals.
There are clients (indexed from to ) that Mike needs to help. There are operations of the following types:
-
Add a country to the blacklist of all clients. Blacklisting a country blocks all IPs that belong to this country and any countries merged with it.
-
Add the IP interval to the blacklist of all clients.
-
For a specific client, add a country and any countries merged with it to the blacklist.
-
For a specific client, add the IP interval to the blacklist.
-
For a specific client, add a country and any countries merged with it to the whitelist. Whitelisting a country adds all IPs that belong to this country and any countries merged with it to the whitelist. Note that the whitelist has higher priority than any previous or future blacklist for this client. That is, if an IP is whitelisted for a client, it will never be affected by any blacklist operations before or after.
-
For a specific client, add the IP interval to the whitelist. Note that the whitelist has higher priority than any previous or future blacklist for this client. That is, if an IP is whitelisted for a client, it will never be affected by any blacklist operations before or after.
-
Countries and are merged together.
-
Query how many IPs a client can access within the interval .
Input Format
The first line contains three integers . It is guaranteed that , , .
In the next lines, the first integer indicates that the IP set of the -th country is the union of intervals. Then integers follow to describe these intervals. These numbers are between and . It is guaranteed that .
In the next lines, the first integer indicates the operation type. Then the corresponding parameters for each operation are given:
1: , with .
2: , with .
3: , with , .
4: , with , .
5: , with , .
6: , with , .
7: , with , .
8: , with , .
Output Format
For each query, output one line with the answer.
2 1 12
1 1 100
1 500 1000
8 0 1 1000
1 0
2 800 900
8 0 1 1000
7 0 1
3 0 0
8 0 1 1000
4 0 200 400
8 0 1 1000
5 0 1
6 0 95 499
8 0 1 1000
1000
799
399
198
1000
Hint
Translated by ChatGPT 5