#K79202. Town Management System
Town Management System
Town Management System
You are required to implement a town management system that manages information about houses and roads. Each house has an integer address and the town has several undirected roads connecting pairs of houses.
The system must support the following operations:
- Update Address: Given a house index k and a new address x, update the address of the k-th house.
- Check Road: Given two houses y and z, check if there is a direct road connecting them. Output
YES
if there is a road, otherwise outputNO
. - Count Houses in Range: Given two integers li and ri, count the number of houses with addresses in the inclusive range \(l_i \leq a \leq r_i\).
You will be given the initial addresses of the houses and the details of all roads. Then, a series of queries will be provided. For update queries, no output is expected. For the other two types, output the result of the query in the order they are given.
inputFormat
The first line contains two integers n
and m
, representing the number of houses and the number of roads, respectively.
The second line contains n
integers, representing the initial addresses of the houses.
The next m
lines each contain two integers u
and v
, indicating that there is a road between house u
and house v
.
The following line contains an integer q
, the number of queries.
Each of the next q
lines contains a query in one of the following formats:
1 k x
: Update the address of the k-th house to x.2 y z
: Check if there is a direct road between house y and house z. OutputYES
orNO
.3 li ri
: Count the number of houses with addresses in the range [li, ri] (\(l_i \leq a \leq r_i\)).
All input is read from standard input (stdin).
outputFormat
For each query of type 2 or type 3, output the result on a separate line. For type 2 queries, output either YES
or NO
. For type 3 queries, output the integer count of houses whose addresses lie in the specified range.
Output should be written to standard output (stdout).
## sample5 4
12 23 34 45 56
1 2
2 3
4 5
1 4
5
1 3 29
2 2 3
3 10 40
3 35 50
2 1 4
YES
3
1
YES
</p>