Relocation

시간 제한1초메모리 제한1024 MB

요약
회사 위치 배열을 유지하면서 한 회사의 위치를 갱신하고 두 회사 사이의 거리를 답하는 문제입니다.
난이도

쉬움10점 중 2점

유형
배열, 구현
정답자
아직 제출이 없습니다

문제

In the faraway country of Lineland, tech companies are starting to take over! Every week, it seems that tech companies sprout from the ground, merge, get acquired, or go under. For software engineers looking for new jobs in Lineland, it can be difficult to even find the companies where they’re interviewing.

To solve this issue, you’re going to make 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 supremely useful, as companies change offices all the time and it’s difficult to stay completely up to date. By centralizing this information, your company is going to make the world a better place.

Since Lineland is organized around a single line, the location of a company can be given by a single coordinate. The distance between any two companies is equal to the distance between their two coordinates.

Your job is to handle two kinds of user requests to the company’s flagship app. One kind of request updates the address of a company, the other requests the shortest distance between two companies.

입력

The first line has two positive space-separated integers NN and QQ: the number of companies the app tracks (2≤N≤100,0002 \le N \le 100\\, 000), and the number of requests to process (1≤Q≤100,0001 \le Q \le 100\\, 000). The next line has NN space-separated integers 1≤X_i≤1091 \le X\_ i \le 10^9, which are the initial locations of the NN companies, given in order from i=1i=1 to i=Ni=N.

Each of the next QQ lines has 33 space-separated integers, taking one of the following forms:

  • 11 CC XX, which means that company CC moves its location to XX, or

  • 22 AA BB, which is a query for the distance between companies AA and BB.

It is guaranteed that 1≤A,B,C≤N1 \leq A, B, C \leq N and 1≤X≤1091 \leq X \leq 10^9. It is possible two companies can share the same location. It is also guaranteed there is at least one query of type 22.

출력

For each query of type 22, print the distance between companies AA and BB.

힌트

In the first query, Company 22 moves to location 1010. Then the app is asked for the distance between company 44 and company 55, which is 33. The next query is the distance between companies 11 and 33, which is also 33. A number of updates and queries follow.

예제1

  1. 예제 1

    입력
    5 10
    5 2 8 1 4
    1 2 10
    2 4 5
    2 1 3
    1 4 3
    2 1 5
    2 5 2
    1 4 1
    2 2 4
    1 3 15
    2 4 1
    
    예상 출력
    3
    3
    1
    6
    9
    4