-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelocation.py
28 lines (23 loc) · 940 Bytes
/
relocation.py
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
# Problem: https://open.kattis.com/problems/relocation
# Init vars and get input
params = input("").split(" ")
n = int(params[0])
q = int(params[1])
start_loc = input("").split(" ")
business_loc = [0] * (n + 1)
# Copy the list passed in with start locations. This is to make sure
# they are stored as ints and also to shift everything by one so the
# index matches the business number (0 will be "empty")
for i in range(n):
business_loc[i+1] = int(start_loc[i])
# Iterate through each query
for i in range(q):
params = input("").split(" ")
# If query begins with a 1, the next value is business number
# and next is its move location
if params[0] == "1":
business_loc[int(params[1])] = int(params[2])
# If query begins with a 2, print the distance between the
# businesses (indicated by following two values)
else:
print(abs(business_loc[int(params[1])] - business_loc[int(params[2])]))