-
Notifications
You must be signed in to change notification settings - Fork 0
/
ICPCPracticeProb5.py
49 lines (44 loc) · 1.29 KB
/
ICPCPracticeProb5.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
n , q =[int(x) for x in input().split()]
ax = [int(x) for x in input().split()]
idol = [int(x) for x in input().split()]
dp = [[-1,-1] for x in range(n)]
def fun(x):
if x==1:
return [ax[0],1]
else:
if dp[idol[x-2]][0]!=-1:
return [dp[idol[x-2]]]
else:
if fun(idol[x-2]).__getitem__(0)+1<ax[x-1]:
dp[x-1][0]=ax[x-1]
dp[x-1][1]=1
elif fun(idol[x-2]).__getitem__(0)+1>ax[x-1]:
dp[x-1][0]=fun(idol[x-2]).__getitem__(0)+1
dp[x-1][1]=dp[idol[x-2]][1]
else:
dp[x-1][0]=fun(idol[x-2]).__getitem__(0)+1
dp[x-1][1]=dp[idol[x-2]][1]+1
return dp[x-1]
for i in range(q):
temp = [int(x) for x in input().split()]
if temp[0] == 0:
axtemp = ax[0]
ax[temp[1]]=temp[2]
dp = [[-1, -1] for x in range(n)]
else:
ans = fun(temp[1])
print(ans[0]," ",ans[1])
# def fun(x):
# if dp[idol[x]] != -1:
# return dp[x]
# else:
# if fun(x)
#
# for i in range(q):
# temp = [int(x) for x in input().split()]
# if temp[0]==0:
# axtemp = ax[0]
# ax = [x+temp[1]-axtemp for x in ax]
# dp = [-1 for x in range(n)]
# else:
# #for j,e in enumerate(ax):