Relocation
Time limit1sMemory limit1024 MB
Each company has a coordinate that can be updated, and each query asks for the absolute difference between two companies' coordinates.
- Level
Easy2 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
In the faraway country of Lineland, tech companies keep appearing. Every week, new companies are founded, merged, acquired, or shut down. Software engineers looking for new jobs in Lineland often cannot even find the offices of the companies where they are interviewing.
To solve this, you are building a new tech company. The product is simple: using deep neural blockchains in the cloud, your app finds the distance between any two tech companies in Lineland. This is useful because companies change offices all the time, and keeping up with those moves is hard. By centralizing this information, your company will make the world a better place.
Lineland is organized around a single line, so the location of each company is a single coordinate. The distance between two companies is the distance between their two coordinates.
Your job is to handle two kinds of requests sent to the company's flagship app. One kind updates the address of a company. The other asks for the shortest distance between two companies.
Input
The first line has two positive integers and , separated by a space. is the number of companies the app tracks (), and is the number of requests to process ().
The next line has integers (), the initial locations of the companies in order from to .
Each of the next lines has three integers in one of the following forms:
1 C X: company moves to location .2 A B: a query for the distance between companies and .
It is guaranteed that and . Two companies may share the same location. There is at least one query of type 2.
Output
For each query of type 2, print the distance between companies and on its own line.
Hint
In the first query, company 2 moves to location 10. The app is then asked for the distance between company 4 and company 5, which is 3. The next query asks for the distance between companies 1 and 3, which is also 3. Several more updates and queries follow.