結果

問題 No.1623 三角形の制作
ユーザー c-yanc-yan
提出日時 2021-07-24 12:35:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,651 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 2,944 ms
コンパイル使用メモリ 86,828 KB
実行使用メモリ 293,588 KB
最終ジャッジ日時 2023-09-26 23:58:43
合計ジャッジ時間 20,566 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
76,388 KB
testcase_01 AC 88 ms
76,528 KB
testcase_02 AC 1,611 ms
291,328 KB
testcase_03 AC 1,615 ms
290,368 KB
testcase_04 AC 1,576 ms
290,172 KB
testcase_05 AC 1,632 ms
288,504 KB
testcase_06 AC 1,570 ms
286,496 KB
testcase_07 AC 1,586 ms
290,208 KB
testcase_08 AC 1,555 ms
287,228 KB
testcase_09 AC 1,604 ms
286,476 KB
testcase_10 AC 1,651 ms
293,588 KB
testcase_11 AC 1,612 ms
292,644 KB
testcase_12 AC 124 ms
97,396 KB
testcase_13 AC 128 ms
99,624 KB
testcase_14 AC 125 ms
96,848 KB
testcase_15 AC 194 ms
142,652 KB
testcase_16 AC 194 ms
142,572 KB
testcase_17 AC 196 ms
142,508 KB
testcase_18 AC 194 ms
139,272 KB
testcase_19 AC 141 ms
109,516 KB
testcase_20 AC 87 ms
76,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BinaryIndexedTree:
    def __init__(self, size):
        self._data = [0] * size

    def add(self, i, x):
        data = self._data
        i += 1
        n = len(data)
        while i <= n:
            data[i - 1] += x
            i += i & -i

    def _sum(self, stop):
        data = self._data
        result = 0
        i = stop
        while i > 0:
            result += data[i - 1]
            i -= i & -i
        return result

    def range_sum(self, start, stop):
        return self._sum(stop) - self._sum(start)


n = int(input())
r = list(map(int, input().split()))
g = list(map(int, input().split()))
b = list(map(int, input().split()))

rr = [0] * 3001
for i in r:
    rr[i] += 1

gg = [0] * 3001
for i in g:
    gg[i] += 1

bb = [0] * 3001
for i in b:
    bb[i] += 1

gb = [[] for _ in range(3001)]
for i in range(1, 3001):
    x = gg[i]
    if x == 0:
        continue
    for j in range(1, 3001):
        y = bb[j]
        if y == 0:
            continue
        gb[max(i, j)].append((i << 12) + j)

bit = BinaryIndexedTree(6001)
result = 0
for i in range(1, 3001):
    for x in gb[i]:
        j = x >> 12
        k = x & 4095
        bit.add(j + k, gg[j] * bb[k])
    result += rr[i] * bit.range_sum(i + 1, 6001)
print(result)
0