結果
問題 | No.1524 Upward Mobility |
ユーザー | gorugo30 |
提出日時 | 2021-05-28 22:34:22 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,794 bytes |
コンパイル時間 | 546 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 119,228 KB |
最終ジャッジ日時 | 2024-11-07 09:58:32 |
合計ジャッジ時間 | 19,887 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 430 ms
113,268 KB |
testcase_01 | AC | 440 ms
113,384 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 709 ms
113,432 KB |
testcase_11 | AC | 400 ms
116,744 KB |
testcase_12 | AC | 410 ms
116,748 KB |
testcase_13 | AC | 711 ms
117,376 KB |
testcase_14 | AC | 683 ms
116,236 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 50 ms
54,912 KB |
testcase_23 | AC | 49 ms
54,528 KB |
testcase_24 | AC | 49 ms
54,656 KB |
testcase_25 | AC | 48 ms
54,528 KB |
testcase_26 | AC | 49 ms
54,528 KB |
testcase_27 | AC | 49 ms
54,400 KB |
testcase_28 | AC | 49 ms
54,400 KB |
testcase_29 | AC | 319 ms
118,964 KB |
testcase_30 | AC | 324 ms
119,096 KB |
testcase_31 | AC | 485 ms
119,228 KB |
testcase_32 | WA | - |
ソースコード
class segtree(): n=1 size=1 log=2 d=[0] op=None e=10**15 def __init__(self,V,OP,E): self.n=len(V) self.op=OP self.e=E self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] for i in range(self.n): self.d[self.size+i]=V[i] for i in range(self.size-1,0,-1): self.update(i) def set(self,p,x): assert 0<=p and p<self.n p+=self.size self.d[p]=x for i in range(1,self.log+1): self.update(p>>i) def get(self,p): assert 0<=p and p<self.n return self.d[p+self.size] def prod(self,l,r): assert 0<=l and l<=r and r<=self.n sml=self.e smr=self.e l+=self.size r+=self.size while(l<r): if (l&1): sml=self.op(sml,self.d[l]) l+=1 if (r&1): smr=self.op(self.d[r-1],smr) r-=1 l>>=1 r>>=1 return self.op(sml,smr) def all_prod(self): return self.d[1] def max_right(self,l,f): assert 0<=l and l<=self.n assert f(self.e) if l==self.n: return self.n l+=self.size sm=self.e while(1): while(l%2==0): l>>=1 if not(f(self.op(sm,self.d[l]))): while(l<self.size): l=2*l if f(self.op(sm,self.d[l])): sm=self.op(sm,self.d[l]) l+=1 return l-self.size sm=self.op(sm,self.d[l]) l+=1 if (l&-l)==l: break return self.n def min_left(self,r,f): assert 0<=r and r<self.n assert f(self.e) if r==0: return 0 r+=self.size sm=self.e while(1): r-=1 while(r>1 & (r%2)): r>>=1 if not(f(self.op(self.d[r],sm))): while(r<self.size): r=(2*r+1) if f(self.op(self.d[r],sm)): sm=self.op(self.d[r],sm) r-=1 return r+1-self.size sm=self.op(self.d[r],sm) if (r& -r)==r: break return 0 def update(self,k): self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) N = int(input()) P = [0] + list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = [[] for i in range(N)] for i in range(N): A[i] -= 1 P[i] -= 1 if i > 0: C[P[i]].append(i) m = [10 ** 9] * N M = [-1] * N et = [] from collections import deque st = deque([0]) i = 0 while len(st): v = st.pop() if v < 0: v = ~v if et[-1] == v: continue et.append(v) m[v] = min(m[v], i) M[v] = max(m[v], i) i += 1 else: et.append(v) m[v] = min(m[v], i) M[v] = max(m[v], i) i += 1 for c in C[v]: st.append(~v) st.append(~c) st.append(c) V = [i for i in range(N)] V.sort(key = lambda x: -A[x]) seg = segtree([0] * len(et), lambda x, y: max(x, y), 0) dp = [0] * N for v in V: for c in C[v]: dp[v] += seg.prod(m[c], M[c] + 1) dp[v] += B[v] seg.set(m[v], dp[v]) ans = 0 depth = [-1] * N qu = deque([0]) while len(qu): v = qu.popleft() for c in C[v]: qu.append(c) depth[c] = depth[v] + 1 V.sort(key = lambda x: -depth[x]) for v in V: tmp = 0 for c in C[v]: tmp += seg.prod(m[c], M[c] + 1) dp[v] = max(dp[v], tmp) seg.set(m[v], dp[v]) print(max(dp))