結果

問題 No.1282 Display Elements
ユーザー titiatitia
提出日時 2020-11-06 22:13:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 585 ms / 2,000 ms
コード長 776 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 10,768 KB
実行使用メモリ 44,612 KB
最終ジャッジ日時 2023-09-29 18:55:37
合計ジャッジ時間 5,645 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,884 KB
testcase_01 AC 14 ms
7,796 KB
testcase_02 AC 14 ms
7,792 KB
testcase_03 AC 14 ms
7,792 KB
testcase_04 AC 14 ms
7,732 KB
testcase_05 AC 15 ms
7,788 KB
testcase_06 AC 15 ms
7,868 KB
testcase_07 AC 15 ms
7,792 KB
testcase_08 AC 15 ms
7,844 KB
testcase_09 AC 14 ms
7,732 KB
testcase_10 AC 16 ms
8,204 KB
testcase_11 AC 16 ms
8,320 KB
testcase_12 AC 15 ms
7,872 KB
testcase_13 AC 16 ms
8,372 KB
testcase_14 AC 17 ms
8,412 KB
testcase_15 AC 530 ms
43,060 KB
testcase_16 AC 182 ms
20,312 KB
testcase_17 AC 406 ms
30,224 KB
testcase_18 AC 248 ms
26,088 KB
testcase_19 AC 341 ms
23,496 KB
testcase_20 AC 342 ms
23,196 KB
testcase_21 AC 585 ms
44,612 KB
testcase_22 AC 367 ms
23,196 KB
testcase_23 AC 565 ms
44,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
    
0