#P16697. [CSPro 29] 星际网络II

    ID: 18750 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>线段树2023颜色段均摊(珂朵莉树 ODT)离散化CSPro

[CSPro 29] 星际网络II

Background

Luogu’s testdata is only for non-official communication and is not official testdata. Official judging link: https://www.cspro.org/.

Problem Description

With the further construction and expansion of the interstellar network, a new problem has appeared for network engineers: the address space is not enough! Originally, the interstellar network used the traditional IPv6 protocol. Although it provides about 21282^{128} available addresses, when facing the vast universe and the explosive growth of network users, even such a huge address space will one day be exhausted.

The development of a new communication protocol was assigned to the famous holy land of network technology—Xixiaifu Star. Finally, after 2333 years of unremitting effort, the engineers of Xixiaifu Star designed a new protocol—the “Xixiaifu IP Protocol”, also called IPxxaf.

In the IPxxaf protocol, an address consists of nn binary bits, where nn is a multiple of 1616. For daily representation, it uses a hexadecimal notation similar to IPv6, with every 44 bits separated by :. For example, when n=32n = 32, the address is 2a00:0001, which represents the binary address 0010 1010 0000 0000 0000 0000 0000 0001. Note that there will be no cases like IPv6 where leading 0 in each group is omitted, or a segment of 0 is omitted using ::.

For convenience, let num(s)\text{num}(s) denote the nn-bit binary number of address ss with higher bits first and lower bits last. A “continuous block of addresses” refers to a series of addresses whose num(s)\text{num}(s) values form a continuous interval.

The network administrator of Xixiaifu Star is responsible for address allocation and management. At the beginning, the entire address space is unallocated. Users may apply to the administrator for some addresses at any time:

  • 1 id l r: User id\text{id} applies for a continuous address block within the range l∼rl \sim r (including ll and rr, same below).

During an address application, the administrator must first check whether the addresses are available. If all requested addresses are unallocated, the check passes; if there exists any address that has already been allocated to other users, the check fails.

However, there is a special case: none of the requested addresses has been allocated to other users, but some of them were previously allocated to the same user. In this case, the check can be considered passed; but if all requested addresses were previously allocated to this user, then the check fails.

If the above check passes, the administrator returns YES and allocates the requested addresses to the user. Otherwise, the administrator returns NO and does not change the existing allocation.

The network administrator also needs to periodically check address allocation status. Specifically, there are the following two operations:

  • 2 s: Query which user address ss is allocated to. If unallocated, the result is 00.
  • 3 l r: Check whether all addresses in the range l∼rl \sim r are completely allocated to a single user. If yes, output that user’s id; otherwise, output 00.

During the operation of the whole network, there are qq applications and queries in total. As an important network technical consultant on Xixiaifu Star, you need to process each operation in order and output the corresponding result.

Input Format

Read from standard input.

The first line contains 22 positive integers n,qn, q.

The next qq lines each contain one operation in the formats described above. Here id\text{id} is a positive integer, and l,r,sl, r, s are all IPxxaf address strings, where hexadecimal digits use numbers and lowercase letters.

Output Format

Write to standard output.

Output qq lines. Each line is a non-negative integer or a string, representing the result of the operation.

For operation 11, output YES or NO. For operations 2,32, 3, output a non-negative integer.

32 12
1 1 0001:8000 0001:ffff
2 0001:a000
3 0001:c000 0001:ffff
1 2 0000:0000 000f:ffff
2 0000:1000
1 1 0001:8000 0001:8fff
1 2 0000:0000 0000:ffff
2 0000:1000
1 1 0002:8000 0002:ffff
3 0001:8000 0002:ffff
1 1 0001:c000 0003:ffff
3 0001:8000 0002:ffff
YES
1
1
NO
0
NO
YES
2
YES
0
YES
1

Hint

Explanation of Sample 1

At the 4th operation, part of the addresses applied by user 22 had already been allocated to user 11, so the application fails.

At the 6th operation, all addresses applied by user 11 had already been allocated to user 11, so the application fails.

At the 11th operation, part of the addresses applied by user 11 had already been allocated to user 11, and the remaining addresses were still unallocated, so the application succeeds.

Constraints

For all data, n≤512n \le 512, q≤5×104q \le 5 \times 10^4, nn is a multiple of 1616, id≤q\text{id} \le q. For operations 1,31,3, it is guaranteed that num(l)≤num(r)\text{num}(l) \le \text{num}(r).

Test Point ID n≤n \le q≤q \le Special Properties
1∼41 \sim 4 1616 200200 None
5∼6 5 \sim 6 64 64 ^ ^
7∼97 \sim 9 512512
10∼1110 \sim 11 1616 2000020000
12∼1312 \sim 13 6464 5000050000
14∼1614 \sim 16 512512 ^ For all operations 11, all id\text{id} are pairwise distinct
17∼2017 \sim 20 ^ None

Translated by ChatGPT 5