#P4175. [CTSC2008] 网络管理

    ID: 3114 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>线段树平衡树树状数组树链剖分,树剖主席树

[CTSC2008] 网络管理

Description

Company M is a very large multinational with branches or departments in many countries. To let the nn departments distributed around the world work together, the company built a communication network that connects the entire company.

The network consists of nn routers and n1n-1 high-speed fiber-optic cables. Each department has a dedicated router; all machines in the department’s local area network connect to this router, and then communicate with other departments through this communication subnet. The network structure guarantees that between any two routers there exists a direct or indirect path for communication.

The fiber-optic cables transmit data so fast that the latency on the cables can be ignored. However, due to router aging, exchanging data on the routers introduces significant delay. The communication delay between two routers is determined by the maximum exchange delay among all routers on the communication path between the two routers.

As an intern in Company M’s network division, you are asked to write a simple program to monitor the company’s network status. The program must be able to update the network status at any time (changes in routers’ data exchange delay), and, upon queries, report the delay of the kk-th largest-delay router on the path between two routers.

Task: Your program reads from the input file the connectivity of the nn routers and n1n-1 fiber-optic cables, the initial data exchange delay tit_i of each router, and qq queries (or state changes). Process the qq queries in order; each is one of:

  1. Due to an upgrade or a new fault, a router’s data exchange delay changes.
  2. Query the delay of the kk-th largest-delay router on the path between routers aa and bb.

Input Format

The first line contains two integers nn and qq, the total number of routers and the total number of queries.

The second line contains nn integers; the ii-th number is the initial data exchange delay tit_i of router ii.

The next n1n-1 lines each contain two integers xx and yy, indicating there is a fiber-optic cable connecting router xx and router yy.

Then follow qq lines, each containing three integers k,a,bk, a, b.

If k=0k=0, router aa changes state: its data exchange delay changes from tat_a to bb.

If k>0k>0, query the kk-th largest delay among all routers on the path from aa to bb (including aa and bb). Note that aa can be equal to bb; in this case, the path contains only one router.

Output Format

For each query of the second type (i.e., k>0k>0), output one line containing a single integer, the corresponding delay. If the routers on the path are fewer than kk, output invalid request!.

5 5
5 1 2 3 4
3 1
2 1
4 3
5 3
2 4 5
0 1 2
2 2 3
2 1 4
3 3 5
3
2
2
invalid request!

Hint

Constraints
For 100%100\% of the testdata, 1n,q800001 \le n, q \le 80000, 0kn0 \le k \le n, and at any time the delay of any router is less than 10810^8.

Translated by ChatGPT 5