結果
問題 | No.1282 Display Elements |
ユーザー | titia |
提出日時 | 2020-11-06 22:13:05 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 829 ms / 2,000 ms |
コード長 | 776 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 47,036 KB |
最終ジャッジ日時 | 2024-07-22 12:59:16 |
合計ジャッジ時間 | 6,938 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
import sys input = sys.stdin.readline N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) compression_dict={a: ind+2 for ind, a in enumerate(sorted(set(A)|set(B)))} A=sorted([compression_dict[a] for a in A]) B=[compression_dict[b] for b in B] LEN=3*N BIT=[0]*(3*N+1) # 1-indexedなtree def update(v,w): # index vにwを加える while v<=LEN: BIT[v]+=w v+=(v&(-v)) # 自分を含む大きなノードへ. たとえばv=3→v=4 def getvalue(v): # [1,v]の区間の和を求める ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v)) # 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ return ANS ANS=0 for i in range(N): update(B[i],1) ANS+=getvalue(A[i]-1) print(ANS)