Click Here to go back to the homepage.

Relocation Solution:


import java.util.ArrayList;
import java.util.Scanner;

class Kattis{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int companies = sc.nextInt();
    int queries = sc.nextInt();
    ArrayList<Integer> locations = new ArrayList<>();
    locations.add(0);
    for(int i = 0; i < companies; i++){
      locations.add(sc.nextInt());
    }
    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < queries; i++){
      int arr1 = sc.nextInt();
      int arr2 = sc.nextInt();
      int arr3 = sc.nextInt();
      if(arr1==2){
        sb.append(Math.abs(
            locations.get(arr2) - locations.get(arr3)))
            .append(System.lineSeparator());
      }
      else{
        locations.set(arr2, arr3);
      }
    }
    System.out.print(sb.toString());
  }
}