結果

問題 No.1623 三角形の制作
ユーザー c-yanc-yan
提出日時 2021-07-24 12:27:37
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,217 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 429,836 KB
最終ジャッジ日時 2023-09-26 23:41:00
合計ジャッジ時間 26,703 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
76,224 KB
testcase_01 AC 86 ms
76,348 KB
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 120 ms
97,320 KB
testcase_13 AC 125 ms
99,460 KB
testcase_14 AC 122 ms
96,780 KB
testcase_15 AC 191 ms
142,548 KB
testcase_16 AC 192 ms
142,520 KB
testcase_17 AC 190 ms
142,512 KB
testcase_18 AC 188 ms
139,484 KB
testcase_19 AC 139 ms
109,256 KB
testcase_20 AC 86 ms
76,080 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
        z = max(i, j)
        gb[z].append((i + j, x * y))

bit = BinaryIndexedTree(6001)
result = 0
for i in range(1, 3001):
    for x, y in gb[i]:
            bit.add(x, y)
    result += rr[i] * bit.range_sum(i + 1, 6001)
print(result)
0