結果
問題 | No.1115 二つの数列 / Two Sequences |
ユーザー | first_vil |
提出日時 | 2020-07-18 17:46:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 161 ms / 2,000 ms |
コード長 | 1,149 bytes |
コンパイル時間 | 880 ms |
コンパイル使用メモリ | 86,748 KB |
実行使用メモリ | 101,232 KB |
最終ジャッジ日時 | 2023-08-20 18:11:55 |
合計ジャッジ時間 | 6,798 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 87 ms
77,776 KB |
testcase_01 | AC | 59 ms
71,496 KB |
testcase_02 | AC | 59 ms
71,128 KB |
testcase_03 | AC | 146 ms
100,760 KB |
testcase_04 | AC | 156 ms
100,432 KB |
testcase_05 | AC | 148 ms
101,232 KB |
testcase_06 | AC | 142 ms
99,960 KB |
testcase_07 | AC | 154 ms
99,968 KB |
testcase_08 | AC | 86 ms
77,768 KB |
testcase_09 | AC | 116 ms
93,728 KB |
testcase_10 | AC | 145 ms
100,360 KB |
testcase_11 | AC | 58 ms
71,276 KB |
testcase_12 | AC | 154 ms
100,192 KB |
testcase_13 | AC | 153 ms
100,556 KB |
testcase_14 | AC | 161 ms
100,216 KB |
testcase_15 | AC | 60 ms
71,192 KB |
testcase_16 | AC | 58 ms
70,924 KB |
testcase_17 | AC | 60 ms
71,404 KB |
testcase_18 | AC | 61 ms
71,080 KB |
testcase_19 | AC | 61 ms
71,396 KB |
testcase_20 | AC | 59 ms
71,280 KB |
testcase_21 | AC | 60 ms
71,224 KB |
testcase_22 | AC | 61 ms
71,324 KB |
testcase_23 | AC | 85 ms
77,684 KB |
testcase_24 | AC | 112 ms
85,124 KB |
testcase_25 | AC | 140 ms
99,972 KB |
testcase_26 | AC | 95 ms
79,340 KB |
testcase_27 | AC | 115 ms
88,236 KB |
testcase_28 | AC | 131 ms
93,764 KB |
testcase_29 | AC | 153 ms
97,856 KB |
testcase_30 | AC | 156 ms
100,024 KB |
testcase_31 | AC | 100 ms
81,012 KB |
testcase_32 | AC | 91 ms
78,668 KB |
testcase_33 | AC | 135 ms
99,912 KB |
testcase_34 | AC | 61 ms
71,352 KB |
testcase_35 | AC | 60 ms
71,216 KB |
testcase_36 | AC | 60 ms
71,336 KB |
testcase_37 | AC | 59 ms
71,208 KB |
testcase_38 | AC | 60 ms
71,308 KB |
testcase_39 | AC | 60 ms
71,304 KB |
ソースコード
class segtree: def __init__(self,_n): self.n=1 while self.n<_n: self.n<<=1 self.dat=[0]*(self.n<<1) for i in range(self.n-1,0,-1): self.dat[i]=self.dat[i<<1]+self.dat[i<<1|1] def update(self,k,a): k+=self.n self.dat[k]+=a while 1<k: k>>=1 self.dat[k]=self.dat[k<<1]+self.dat[k<<1|1] def value(self,l,r): res=0 l+=self.n r+=self.n while l<r: if l&1: res+=self.dat[l] l+=1 if r&1: r-=1 res+=self.dat[r] l>>=1 r>>=1 return res def main(): import sys input=sys.stdin.readline n=int(input()) a=(lambda x:[i-1 for i in x])(list(map(int,input().split()))) b=(lambda x:[i-1 for i in x])(list(map(int,input().split()))) p=[0]*n for i in range(n): p[b[i]]=i for i in range(n): a[i]=p[a[i]] ans=0 seg=segtree(n) for i in a: ans+=seg.value(i+1,n) seg.update(i,1) print(ans) if __name__ == '__main__': main()