Postal Reform
Time limit2sMemory limit1024 MB
Given a tree of city heights, process point updates to tower heights and answer the maximum height on the path between two cities.
- Level
Medium6 of 10
- Topics
- Tree, Segment tree
- Solved
- No attempts yet
Problem
Flatland is going through a season of reforms. Recently the roads were reformed so that every city can be reached from any other city, and there is exactly one simple path between any two cities. The wizards were also reformed, so each city has exactly one wizard. Now the postal system is being reformed.
The newly founded postal agency "Ex-Fedya" offers a unique service called the collective parcel. This service lets you send parcels to the residents of all cities on some path, at the price of a regular parcel. Surprisingly, only the wizards of Flatland have started using it, and they send each other magic cacti in large numbers.
The agency has run into an unexpected problem. All wizards live in towers, and they do not build stairs to them. On top of that, they change the height of their towers from time to time. So to deliver a parcel to a wizard who lives in a tower of height , the courier must carry at least meters of rope.
You are in charge of logistics. Given the tower heights and their changes, you must find the minimum length of rope that must be issued to a courier who delivers parcels between cities and .
Input
The first line contains , the number of cities in Flatland (). The second line contains positive integers, none exceeding , the tower heights in the cities. The next lines each contain two integers and , describing the -th road (, ). The next line contains , the number of queries (). Each of the next lines is one of the following:
- A notice from the wizard in city that the height of his tower is now , in the form (, ).
- A request from the courier for rope to deliver parcels to every city on the path from to , inclusive, in the form ().
Output
For each delivery query, print the minimum length of rope that must be issued to the courier.