#P8353. [SDOI/SXOI2022] 无处存储
[SDOI/SXOI2022] 无处存储
Background
Abusing the judging of this problem will result in account suspension. Please note the unusual time and memory limits and the number of test cases.
Problem Description
Little came up with a data structure problem, so it first built a tree with node weights:
Given a tree of size , with nodes numbered from to , for each node , its parent is denoted as . Also, each node has a node weight , and the initial weights are determined by the input; see the input format for details.
In data structure problems, there should be corresponding update and query operations. On a tree, the simplest two non-trivial operations are of course path add and path sum.
Therefore, you need to support the following two operations:
0 x y v: increase the weights of all nodes on the simple path from to in the tree by .
1 x y: query the sum of weights of all nodes on the simple path from to in the tree.
After writing the problem, Little showed it to Little N, and Little N said:
... This is way too easy. Isn’t this just a heavy-light decomposition template problem?!!
So Little recalled the idea of trading time for memory when first learning OI, and decided that the memory limit of this problem would be 64 MB.
Input Format
The first line contains three positive integers , , , and four non-negative integers , , , .
, , , are used to generate the node weights , using the following recurrence:
$$a_{i}=\left(A a_{i-1}^{2}+B a_{i-1}+C\right) \bmod 2^{32}$$The next line contains positive integers representing .
Then there are lines, each containing several integers in the form 0 x' y' v' or 1 x' y', representing an update or a query.
Here , , are used to force online. The actual operation uses
,
,
,
where is the bitwise XOR operator ^ in C/C++,
,
is the answer of the previous query (if there is no previous query, treat it as ),
and is the bitwise AND operator & in C/C++.
Output Format
Output several lines. Print, in order, the result of each query modulo .
0 10 10 935995202 406705156 7034169 418665824
1 1 1 1 1 1 1 7 2
0 10 3 781084039
1 7 5
0 897574 897583 833116301
1 897583 897572
0 886189 886179 123805569
1 886182 886190
1 145142 145136
1 854537 854538
1 896515 896525
0 879409 879412 746499584
2925376046
3681387943
4240586487
2878147072
2350755335
731736886
Hint
Sample 2 to Sample 15 testdata can be found in the download link below.
In each group of sample testdata above, the constraints of each group match the constraints and properties of the subtask indicated by its input subtask id (except when the input subtask id is ). Also, to avoid possible constant-factor issues, it is guaranteed that the distributed samples (except when the subtask id is ) use a data generation strength comparable to the final test points used for judging in that subtask.
| Subtask ID | Points | Tree Shape | Special Property | ||
|---|---|---|---|---|---|
| 1 | 2 | C | W | ||
| 2 | A | ||||
| 3 | B | Y | |||
| 4 | |||||
| 5 | |||||
| 6 | |||||
| 7 | |||||
| 8 | |||||
| 9 | 3 | ||||
| 10 | 2 | W | |||
| 11 | |||||
| 12 | |||||
| 13 | |||||
| 14 | |||||
| 15 | |||||
| 16 | 3 | ||||
| 17 | 2 | C | X | ||
| 18 | |||||
| 19 | |||||
| 20 | |||||
| 21 | |||||
| 22 | |||||
| 23 | 3 | ||||
| 24 | 2 | Y | |||
| 25 | |||||
| 26 | |||||
| 27 | |||||
| 28 | |||||
| 29 | |||||
| 30 | 3 | ||||
| 31 | 2 | Z | |||
| 32 | |||||
| 33 | |||||
| 34 | |||||
| 35 | |||||
| 36 | |||||
| 37 | 3 | ||||
| 38 | W | ||||
| 39 | |||||
| 40 | |||||
| 41 | |||||
| 42 | |||||
| 43 | |||||
| 44 | |||||
In the “Tree Shape” column above, means that for all , is generated uniformly at random in . means that for all , . means that the tree shape has no special restriction.
In the “Special Property” column above, means there are no update operations. means for every update operation, . means for every query operation, . means there is no special property.
For of the data, , , , , .
[Hint]
Hints and warnings about the memory limit:
- The program itself may take about 2 to 4 MB of memory (for example, the included libc library). Please avoid using memory too close to the memory limit.
- The provided fast input template takes about 1 MB. Increasing the parameter
Scan reduce the number offreadcalls (thus making it a bit faster), but it will use more memory. If necessary, you may freely adjust the size ofS, or use your own input method. - Note that although recursion itself does not explicitly use much memory, the recursion stack during recursion may still consume memory (you can roughly understand this as the program needing to record parameters and return values at a low level). For example, a recursive function that takes an
intparameter and returns anint, called recursively 100 times, may produce a memory cost equivalent to defining 200intvariables (the exact ratio depends on compiler implementation and optimization). Since the “memory limit” during judging is actually the peak memory usage during execution, too deep recursion may cause MLE. Therefore, use recursion carefully unless you can ensure that the recursion depth will not be too large. - Due to some reasons related to the underlying implementation of file output in computer systems (for example, caching output in memory), the output itself may take some memory. For the output size of this problem, you can assume this part will not exceed 1 MB. However, some debug output (for example, using
cerror printing tostderr) may produce additional memory overhead (even though they will not appear in the output file and thus will not affect judging). Therefore, make sure your final submission does not contain too much debug output. - If you exceed the memory limit for the above reasons, you bear all consequences.
The input size of this problem is large, so you may need to use an efficient input method to avoid TLE due to input inefficiency. For fairness, a fast input template is provided (see the distributed file fast_input.cpp for usage). Notes on the fast output template:
- The provided fast input template takes about 1 MB. The larger
Sis, the faster it is, but the more memory it uses. Please chooseScarefully based on your situation to get the best time-memory balance. - Please ensure there are no variables, functions, namespaces, etc. named
INPUT_SPACEorinnin your code to avoid name conflicts; otherwise compilation will fail. Similarly, some statements like#define gc getchar()may cause internal name conflicts withINPUT_SPACE. If such compilation errors occur, you need to rename the conflicting identifiers. - For this template, input from a file is recommended. If you input from the keyboard, it may become impossible to terminate; in this case, you need to manually input a character at the end of the input that has the same effect as the file terminator (this character must not be adjacent to the numeric characters in the input; it is recommended to put it on a new line). For example, on Windows, this character is
Ctrl+Z. - For C and C++ contestants, this template needs to include the header files
stdio.handcstdio(orbits/stdc++.h) respectively. - For efficiency and code length considerations, the
inn()function can only be used to input an unsigned 32-bit integer type.
To demonstrate the usage of the fast input template and how the weights are generated, a sample program is provided; see the distributed file sample.cpp.
Translated by ChatGPT 5