#P7348. 「MCOI-04」重型管制巡航机
「MCOI-04」重型管制巡航机
Description
A rooted tree is given on the plane, with root , and the depth of the root is .
For a node with depth , its -coordinate is .
For all children of a node, they are ordered from left to right by increasing index. Each edge is a line segment connecting two points.
Each leaf node has a ray parallel to the -axis and extending infinitely in the negative direction, and the root node has a ray parallel to the -axis and extending infinitely in the positive direction.
Any two line segments or rays intersect only at the nodes of the tree.
If you do not understand how this tree is drawn, you can read the explanation of Sample 1.
Given pairs , you now start from point and can move freely on the plane, but you are not allowed to pass through any point other than and . Each time you pass through a line segment or a ray, it costs .
Your goal is to move to point . You need to find the minimum cost incurred during the movement.
Input Format
Direct input would cause an enormous input size, so this problem uses a special input method.
The following random number generator is given:
namespace GenHelper
{
unsigned z1,z2,z3,z4,b;
unsigned rand_()
{
b=((z1<<6)^z1)>>13;
z1=((z1&4294967294U)<<18)^b;
b=((z2<<2)^z2)>>27;
z2=((z2&4294967288U)<<2)^b;
b=((z3<<13)^z3)>>21;
z3=((z3&4294967280U)<<7)^b;
b=((z4<<3)^z4)>>12;
z4=((z4&4294967168U)<<13)^b;
return (z1^z2^z3^z4);
}
}
void srand(unsigned x)
{using namespace GenHelper;
z1=x; z2=(~x)^0x233333333U; z3=x^0x1234598766U; z4=(~x)+51;}
int read()
{
using namespace GenHelper;
int a=rand_()&32767;
int b=rand_()&32767;
return a*32768+b;
}
The first line contains three integers .
The next line contains integers describing the tree structure. The -th number denotes the parent index of node .
Then:
- If , then the next lines in standard input each contain two integers separated by a space, representing the query values and . Let the answer to the previous query be . The actual query you need to process is and , where denotes the XOR operation. If this is the first query, then .
- Otherwise, you need to first compute , and then compute .
Output Format
If , output lines, each being the answer to the corresponding query.
If , output two integers separated by two spaces, representing the XOR of all answers and the sum of all answers, respectively.
9 4 -1
1 1 2 2 2 3 7 7
4 7
7 2
5 2
4 8
1
0
0
1
30 1 -1
1 2 3 4 5 6 7 7 9 9 11 11 12 13 13 14 17 18 19 20 21 19 23 22 22 25 25 28 29
6 30
2
30 10000 20051130
1 2 3 4 5 6 7 7 9 9 11 11 12 13 13 14 17 18 19 20 21 19 23 22 22 25 25 28 29
2 6362
Hint
For the enhanced version, see P7434.
Sample 1 Explanation
In the second query, the actual query is . All other queries satisfy .

- It can be seen that going from to requires passing through one line.
- Going from to does not require passing through any line.
- Going from to does not require passing through any line.
- Going from to requires passing through one line.
- Therefore the answers are .
Constraints
This problem uses bundled testdata.
- Subtask 1 (1 pts): , .
- Subtask 2 (9 pts): , .
- Subtask 3 (10 pts): , .
- Subtask 4 (20 pts): , .
- Subtask 5 (59 pts): .
- Subtask 6 (1 pts): no special constraints.
For of the data: , , , , , and when , .
For of the data, it is guaranteed that .
The IO size may be very large. Please choose appropriate input and output methods.
Notes
Minecraft OI Round 4 B
idea: ClCN solution: ClCN & _Guoyh_ check: _Guoyh_
You ask why AC6 is mixed into MCOI?
Very simple: because ClCN does not play MC.
Translated by ChatGPT 5
京公网安备 11011102002149号