-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrelocation.java
33 lines (31 loc) · 1.39 KB
/
relocation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.io.*;
import java.util.*;
public class relocation {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
ArrayList<Integer> companies = new ArrayList<Integer>();
st = new StringTokenizer(in.readLine());
for(int i = 0; i < n; i++) companies.add(Integer.parseInt(st.nextToken()));
//out.println(companies);
for(int i = 0; i < q; i++) {
st = new StringTokenizer(in.readLine());
int query = Integer.parseInt(st.nextToken());
if(query == 1) {
int company = Integer.parseInt(st.nextToken());
int location = Integer.parseInt(st.nextToken());
companies.set(company - 1, location);
//out.println(companies);
}
else {
int companyA = Integer.parseInt(st.nextToken());
int companyB = Integer.parseInt(st.nextToken());
out.println(Math.abs(companies.get(companyA - 1) - companies.get(companyB - 1)));
}
}
out.close();
}
}