結果

問題 No.1282 Display Elements
ユーザー ygd.ygd.
提出日時 2020-11-06 22:38:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 720 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 126,512 KB
最終ジャッジ日時 2023-09-29 19:16:21
合計ジャッジ時間 7,377 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,320 KB
testcase_01 AC 68 ms
71,304 KB
testcase_02 AC 68 ms
70,956 KB
testcase_03 AC 69 ms
71,072 KB
testcase_04 AC 74 ms
71,364 KB
testcase_05 AC 68 ms
71,376 KB
testcase_06 AC 68 ms
71,340 KB
testcase_07 AC 68 ms
71,316 KB
testcase_08 AC 73 ms
71,184 KB
testcase_09 AC 72 ms
71,364 KB
testcase_10 AC 80 ms
76,572 KB
testcase_11 AC 81 ms
76,324 KB
testcase_12 AC 71 ms
71,488 KB
testcase_13 AC 79 ms
75,792 KB
testcase_14 AC 83 ms
76,564 KB
testcase_15 AC 625 ms
125,560 KB
testcase_16 AC 274 ms
90,712 KB
testcase_17 AC 545 ms
116,280 KB
testcase_18 AC 334 ms
95,368 KB
testcase_19 AC 319 ms
123,728 KB
testcase_20 AC 323 ms
126,512 KB
testcase_21 AC 718 ms
126,376 KB
testcase_22 AC 553 ms
126,244 KB
testcase_23 AC 720 ms
126,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
 
    def to_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= (i & -i)
        return s
 
    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += (i & -i)
 
    def get(self, i, j):
        return self.to_sum(j)-self.to_sum(i-1)

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = []
for i in range(N):
  C.append((A[i],"A",i))
  C.append((B[i],"B",i))
C.sort()
AA = [-1 for _ in range(N)]; BB = [-1 for _ in range(N)]
cnt = 0
prev = 0
for i in range(2*N):
  ID = C[i][2]
  if C[i][0] != prev:
    cnt += 1
  prev = C[i][0]
  if C[i][1] == "A":
    AA[ID] = cnt
  else:
    BB[ID] = cnt
#print(AA)
#print(BB)
AA.sort()
Tree = BIT(2*N)
ans = 0
for i in range(N):
  Tree.add(BB[i],1)
  if AA[i] > 1:
    ans += Tree.get(1,AA[i]-1)
print(ans)
0