luogu#P7834. [ONTAK2010] Peaks 加强版

    ID: 7165 远端评测题 2500ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2010倍增Kruskal 重构树深度优先搜索 DFS可持久化线段树

[ONTAK2010] Peaks 加强版

Background

Original problem link: P4197 Peaks.

Problem Description

Given an undirected graph with nn vertices and mm edges. The weight of vertex ii is aia_i, and each edge has an edge weight.

There are qq queries. Each query gives three integers u,x,ku, x, k. Starting from uu, you may only traverse edges with edge weight x\leq x. Among all vertices that can be reached, output the vertex weight that is the kk-th largest. If it does not exist, output 1-1.

This problem is forced online. That is: for each query, the input is u,x,ku', x', k', then $u = (u' \operatorname{xor} \text{lastans}) \bmod n + 1$, and kk is decrypted in the same way, and x=xxorlastansx = x' \operatorname{xor} \text{lastans}.

Input Format

The first line contains three integers n,m,qn, m, q.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n.

The next mm lines each contain three integers s,t,ws, t, w, representing the two endpoints of an edge and its weight.

The next qq lines each contain three integers u,x,ku', x', k'.

Note: for the first query and for cases with no solution, lastans=0\text{lastans} = 0.

Output Format

For each query, output one line with one integer, representing the required value.

10 11 3
1 2 3 4 5 6 7 8 9 10
1 4 4
2 5 3
9 8 2
7 8 10
7 1 4
6 7 1
6 4 8
2 1 5
10 8 10
3 4 7
3 4 6
0 5 5
1 6 8
7 8 1
1
-1
8

Hint

For 100%100\% of the testdata, 1n1051 \leq n \leq 10^5, 1m,q5×1051 \leq m, q \leq 5 \times 10^5, 1s,tn1 \leq s, t \leq n, 1ai,w1091 \leq a_i, w \leq 10^9, 0u,x,k<2310 \leq u', x', k' < 2^{31}.

Translated by ChatGPT 5