#P3919. 【模板】可持久化线段树 1(可持久化数组)
【模板】可持久化线段树 1(可持久化数组)
Description
As described, you need to maintain an array of length , supporting the following two operations:
- Modify the value at some position on a certain historical version.
- Access the value at some position on a certain historical version.
In addition, each time you perform an operation, a new version is created. The version number equals the current operation index (starting from ; version is the initial array).
For operation , a completely identical version is created without any changes. That is, the version generated by a query is a copy of the version that is being accessed.
Input Format
The first line contains two positive integers , the array length and the number of operations.
The second line contains integers, the initial values of the array (denoted as , ).
Each of the next lines contains or integers, representing one of the two operations (assume the current operation is the -th):
- For operation , the format is
v 1 p c, meaning: based on version , set to . - For operation , the format is
v 2 p, meaning: access the value of in version . Note: the version that is duplicated must be .
Output Format
Output several lines, each being the result of an operation , in order.
5 10
59 46 14 87 41
0 2 1
0 1 1 14
0 1 1 57
0 1 1 88
4 2 4
0 2 5
0 2 4
4 2 1
2 2 2
1 1 5 91
59
87
41
87
88
46
Hint
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
- For of the testdata:
- ;
- ;
- Suppose this is the -th operation, then ;
- .
Sample Explanation
After all operations, a total of versions are generated, numbered , in order:
Version : 59 46 14 87 41.
Version : 59 46 14 87 41.
Version : 14 46 14 87 41.
Version : 57 46 14 87 41.
Version : 88 46 14 87 41.
Version : 88 46 14 87 41.
Version : 59 46 14 87 41.
Version : 59 46 14 87 41.
Version : 88 46 14 87 41.
Version : 14 46 14 87 41.
Version : 59 46 14 87 91.
Translated by ChatGPT 5
京公网安备 11011102002149号