結果

問題 No.1282 Display Elements
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-11-06 21:43:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,003 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 119,244 KB
最終ジャッジ日時 2023-09-29 18:30:54
合計ジャッジ時間 4,295 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,368 KB
testcase_01 AC 70 ms
71,616 KB
testcase_02 AC 73 ms
71,420 KB
testcase_03 AC 71 ms
71,380 KB
testcase_04 AC 72 ms
71,356 KB
testcase_05 WA -
testcase_06 AC 70 ms
71,420 KB
testcase_07 AC 71 ms
71,376 KB
testcase_08 AC 71 ms
71,448 KB
testcase_09 AC 72 ms
71,156 KB
testcase_10 AC 78 ms
76,432 KB
testcase_11 AC 79 ms
76,320 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 132 ms
95,592 KB
testcase_20 AC 142 ms
95,428 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1282
Aはちいさいほうから出すべき

"""

from sys import stdin

def bitadd(a,w,bit): #aにwを加える(1-origin)
    a += 1
    x = a
    while x <= (len(bit)-1):
        bit[x] += w
        x += x & (-1 * x)
 
def bitsum(a,bit): #ind 1~aまでの和を求める
    a += 1
    ret = 0
    x = a
    while x > 0:
        ret += bit[x]
        x -= x & (-1 * x)
    return ret

N = int(stdin.readline())
a = list(map(int,stdin.readline().split()))
b = list(map(int,stdin.readline().split()))

a.sort()

lis = []
dic = {}
for i in b:
    if i not in dic:
        dic[i] = 0
        lis.append(i)
for i in range(len(lis)):
    dic[lis[i]] = i

ans = 0
BIT = [0] * (len(lis)+5)

cnt = 0
for i in a:

    bitadd(dic[b[cnt]] , 1 , BIT)
    
    l = -1
    r = len(lis)

    while r-l != 1:
        m = (l+r)//2
        if lis[m] >= i:
            r = m
        else:
            l = m

    if l != -1:
        ans += bitsum(l,BIT)
    cnt += 1

print (ans)
0