#P3302. [SDOI2013] 森林

    ID: 2351 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数据结构线段树2013山东深度优先搜索DFS主席树

[SDOI2013] 森林

Description

Xiao Z has a forest with NN nodes, and each node has a non-negative integer as its weight. Initially, there are MM edges in the forest.

Xiao Z wants to perform TT operations of two types:

  • Q x y k Query the kk-th smallest weight among all the weights on the path from xx to yy. It is guaranteed that xx and yy are connected, and there are at least kk nodes on this path.
  • L x y Add an edge between nodes xx and yy. It is guaranteed that after this operation, the graph is still a forest.

To make the program online, the input is encrypted. Let lastanslastans be the last printed answer, initially 00.

For an input operation Q x y k, the real operation is Q x^lastans y^lastans k^lastans.

For an input operation L x y, the real operation is L x^lastans y^lastans. Here the operator ^ denotes bitwise XOR, equivalent to xor in Pascal.

Please write a program to help Xiao Z finish these operations.

Input Format

The first line contains a positive integer testcase\mathrm{testcase}, indicating the test point index of the current testdata.

The second line contains three integers N,M,TN, M, T, denoting the number of nodes, the number of initial edges, and the number of operations, respectively.

The third line contains NN non-negative integers, representing the weights of the NN nodes.

The next MM lines each contain two integers xx and yy, indicating that initially there is an undirected edge between xx and yy.

The next TT lines each describe an operation, in the format Q x y k or L x y, as defined above.

Output Format

For each operation of the first type, output a non-negative integer as the answer.

1
8 4 8
1 1 2 2 3 3 4 4
4 7
1 8
2 4
2 1
Q 8 7 3
Q 3 5 1
Q 10 0 0
L 5 4
L 3 2
L 0 7
Q 9 2 5
Q 6 1 6
2 
2
1
4
2

Hint

Sample explanation:

For the first operation Q 8 7 3, at this time lastans=0lastans = 0, so the real operation is Q 8^0 7^0 3^0, i.e., Q 8 7 3. There are 55 nodes on the path from 88 to 77, and their weights are 4,1,1,2,44, 1, 1, 2, 4. Among these weights, the 33-rd smallest is 22, so output 22, and lastanslastans becomes 22.

For the second operation Q 3 5 1, at this time lastans=2lastans = 2, so the real operation is Q 3^2 5^2 1^2, i.e., Q 1 7 3. There are 44 nodes on the path from 11 to 77, and their weights are 1,1,2,41, 1, 2, 4. Among these weights, the 33-rd smallest is 22, so output 22, and lastanslastans becomes 22. The subsequent operations are similar.


Constraints

Test point index Upper bounds of N,M,TN, M, T L operations Q operations Structure
11 2020 N/A N/A N/A
22 200200
343\sim 4 4×1044\times 10^4 No L operations Chain
565\sim 6 8×1048\times 10^4
797\sim 9 Guaranteed k=1k=1 N/A
101110\sim 11 4×1044\times 10^4 N/A
121312\sim 13 8×1048\times 10^4
141514\sim 15 4×1044\times 10^4 No L operations N/A
161716\sim 17 8×1048\times 10^4
1818 4×1044\times 10^4 N/A
192019\sim 20 8×1048\times 10^4

Note: N/A means no special property.

For 100%100\% of the testdata, all node indices are in the range 1N1 \sim N. Each node’s weight 109\le 10^9. M<NM < N.

Translated by ChatGPT 5