#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 00 to 10910^9, and initially all clients can use all IPs. There are NN countries (indexed from 00 to N1N-1). Each country has its own IP set, which can be formally represented as the union of several intervals.

There are MM clients (indexed from 00 to M1M-1) that Mike needs to help. There are QQ operations of the following types:

  1. 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.

  2. Add the IP interval [X,Y][X, Y] to the blacklist of all clients.

  3. For a specific client, add a country and any countries merged with it to the blacklist.

  4. For a specific client, add the IP interval [X,Y][X, Y] to the blacklist.

  5. 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.

  6. For a specific client, add the IP interval [X,Y][X, Y] 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.

  7. Countries XX and YY are merged together.

  8. Query how many IPs a client can access within the interval [X,Y][X, Y].

Input Format

The first line contains three integers N,M,QN, M, Q. It is guaranteed that 1N1041\leq N\leq 10^4, 1M101\leq M\leq 10, 1Q1051\leq Q\leq 10^5.

In the next NN lines, the first integer NiN_i indicates that the IP set of the ii-th country is the union of NiN_i intervals. Then 2×Ni2\times N_i integers follow to describe these intervals. These numbers are between 00 and 10910^9. It is guaranteed that Ni105\sum N_i\leq 10^5.

In the next QQ lines, the first integer indicates the operation type. Then the corresponding parameters for each operation are given:

1: countryIdxcountryIdx, with 0countryIdx<N0≤countryIdx<N.

2: X,YX, Y, with 0XY1090≤X≤Y≤10^9.

3: clientIdx,countryIdxclientIdx, countryIdx, with 0clientIdx<M0≤clientIdx<M, 0countryIdx<N0≤countryIdx<N.

4: clientIdx,X,YclientIdx, X, Y, with 0clientIdx<M0≤clientIdx<M, 0XY1090≤X≤Y≤10^9.

5: clientIdx,countryIdxclientIdx, countryIdx, with 0clientIdx<M0≤clientIdx<M, 0countryIdx<N0≤countryIdx<N.

6: clientIdx,X,YclientIdx, X, Y, with 0clientIdx<M0≤clientIdx<M, 0XY1090≤X≤Y≤10^9.

7: countryIdx1,countryIdx2countryIdx1, countryIdx2, with 0countryIdx1<N0≤countryIdx1<N, 0countryIdx2<N0≤countryIdx2<N.

8: clientIdx,X,YclientIdx, X, Y, with 0clientIdx<M0≤clientIdx<M, 0XY1090≤X≤Y≤10^9.

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