#P3733. [HAOI2017] 八纵八横
[HAOI2017] 八纵八横
Description
The country of Anihc has cities, numbered from to , with city being the capital. Initially, there are highways between cities. Each highway has a non-negative integer economic impact factor, and each highway connects two cities (the endpoints may be the same city). It is guaranteed that any two cities are mutually reachable via highways.
The country is planning the "Eight Verticals and Eight Horizontals" high-speed railway program, which will build some high-speed railways. Each railway also connects two cities (the endpoints may be the same city) and has a non-negative integer economic impact factor. After this program is completed, the country plans to extend the "Belt and Road" to "Belt and Road and Ring" by adding an "Inland Cities Economic Ring," i.e., choosing a path that starts from the capital and follows a sequence of railways and highways, where each railway or highway may be traversed multiple times, and each city may be visited multiple times, finally returning to the capital. Let the GDP of the "Inland Cities Economic Ring" be the XOR of the economic impact factors of the railways and highways traversed along this path in order (an edge traversed multiple times is counted multiple times).
Anihc is discussing the construction plan for "Eight Verticals and Eight Horizontals" and will keep modifying the plan. You are asked to report, in real time, the maximum possible GDP of the "Inland Cities Economic Ring" for the current plan.
Initially, the plan contains no railways. There are the following types of operations:
Add x y z
Add a high-speed railway between cities and with economic impact factor . If this is the -th Add operation, then this railway is named railway .
Cancel k
Cancel railway from the plan. It is guaranteed that railway exists at this moment.
Change k z
Change the economic impact factor of railway to . It is guaranteed that railway exists at this moment.
Input Format
The first line contains integers , denoting the number of cities, the number of highways, and the number of operations.
The next lines each contain integers, describing a highway.
The next lines each contain one operation, in one of the following forms: Add x y z, Cancel k, or Change k z.
Note: All economic impact factors in the input are given in binary, from the most significant bit to the least significant bit.
Output Format
Output one integer on the first line: the maximum possible GDP of the "Inland Cities Economic Ring" if no railway is built.
Then output lines, each containing one integer, where the -th line is the maximum possible GDP of the "Inland Cities Economic Ring" after performing the -th operation with respect to the current plan.
Note: All answers must be output in binary, from the most significant bit to the least significant bit.
4 4 3
1 2 1110
1 3 10
2 4 1110
2 3 100
Add 3 4 11
Change 1 101
Cancel 1
1000
1001
1111
1000
Hint
Constraints and Notes.
Let be the maximum number of bits among the binary representations of all economic impact factors. The testdata satisfies the following table:
| Data Point | Special Property | ||||
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | Only Add operations |
||||
| 6 | |||||
| 7 | |||||
| 8 | |||||
| 9 | |||||
| 10 | |||||
For all testdata it is guaranteed that , , , . Moreover, the number of Add operations does not exceed . There may be multiple highways or railways between two cities, and an edge may have both endpoints at the same city (i.e., multiedges and self-loops).
Translated by ChatGPT 5
京公网安备 11011102002149号