#P9410. City Connectivity and Population Query
City Connectivity and Population Query
City Connectivity and Population Query
We are given n cities arranged in a line. Initially, each city has no population and no connectivity. There are m operations which can be one of the following:
1 x y
: Open a bidirectional flight between city x and city y, connecting them.2 l r a
: Increase the population of every city in the range [l, r] by a.3 x
: Query: If all people from all cities that are connected (i.e. reachable) to city x were to gather in city x, what would be the total population of city x?
Note: The cities are 1-indexed.
inputFormat
The first line contains two integers n and m: the number of cities and the number of operations respectively. Each of the following m lines contains an operation in one of the following formats:
1 x y
2 l r a
3 x
outputFormat
For each operation of type 3, output a single line containing the total population gathered at city x (i.e. the sum of populations in the connected component that includes city x).
sample
5 6
2 1 3 5
3 2
1 2 4
2 4 5 2
3 4
3 1
5
7
5
</p>