結果

問題 No.1282 Display Elements
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-11-06 21:54:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 120,032 KB
最終ジャッジ日時 2023-09-29 18:39:41
合計ジャッジ時間 4,076 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
71,084 KB
testcase_01 AC 63 ms
71,300 KB
testcase_02 AC 65 ms
71,336 KB
testcase_03 AC 63 ms
71,516 KB
testcase_04 AC 65 ms
71,036 KB
testcase_05 AC 64 ms
71,124 KB
testcase_06 AC 65 ms
71,356 KB
testcase_07 AC 63 ms
71,256 KB
testcase_08 AC 64 ms
71,436 KB
testcase_09 AC 66 ms
71,424 KB
testcase_10 AC 71 ms
76,232 KB
testcase_11 AC 73 ms
76,152 KB
testcase_12 AC 67 ms
71,508 KB
testcase_13 AC 79 ms
76,244 KB
testcase_14 AC 79 ms
76,656 KB
testcase_15 AC 218 ms
117,492 KB
testcase_16 AC 127 ms
91,872 KB
testcase_17 AC 189 ms
106,396 KB
testcase_18 AC 138 ms
89,128 KB
testcase_19 AC 119 ms
95,548 KB
testcase_20 AC 122 ms
95,288 KB
testcase_21 AC 224 ms
120,032 KB
testcase_22 AC 151 ms
96,252 KB
testcase_23 AC 225 ms
119,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

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

貪欲ではない?

B 100 50 1
A 101 51 1

"""

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)
lis.sort()
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