結果

問題 No.1623 三角形の制作
ユーザー brthyyjpbrthyyjp
提出日時 2021-07-23 21:49:05
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,892 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 86,684 KB
実行使用メモリ 159,228 KB
最終ジャッジ日時 2023-09-25 21:46:35
合計ジャッジ時間 27,183 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
76,792 KB
testcase_01 AC 98 ms
77,040 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 139 ms
103,712 KB
testcase_13 AC 150 ms
114,420 KB
testcase_14 AC 147 ms
107,652 KB
testcase_15 AC 209 ms
157,688 KB
testcase_16 AC 205 ms
157,516 KB
testcase_17 AC 207 ms
157,564 KB
testcase_18 AC 206 ms
159,228 KB
testcase_19 AC 172 ms
130,264 KB
testcase_20 AC 101 ms
76,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(self.n+1) # 1-indexed

    def init(self, init_val):
        for i, v in enumerate(init_val):
            self.add(i, v)

    def add(self, i, x):
        # i: 0-indexed
        i += 1 # to 1-indexed
        while i <= self.n:
            self.bit[i] += x
            i += (i & -i)

    def sum(self, i, j):
        # return sum of [i, j)
        # i, j: 0-indexed
        return self._sum(j) - self._sum(i)

    def _sum(self, i):
        # return sum of [0, i)
        # i: 0-indexed
        res = 0
        while i > 0:
            res += self.bit[i]
            i -= i & (-i)
        return res

    def lower_bound(self, x):
        s = 0
        pos = 0
        depth = self.n.bit_length()
        v = 1 << depth
        for i in range(depth, -1, -1):
            k = pos + v
            if k <= self.n and s + self.bit[k] < x:
                    s += self.bit[k]
                    pos += v
            v >>= 1
        return pos

    def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.n)]
        return str(arr)

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

from collections import defaultdict

def main():
    n = int(input())
    R = list(map(int, input().split()))
    G = list(map(int, input().split()))
    B = list(map(int, input().split()))

    GC = defaultdict(lambda: 0)
    BC = defaultdict(lambda: 0)
    N = 3*10**3
    RC = [0]*(N+1)
    for g in G:
        GC[g] += 1
    for b in B:
        BC[b] += 1
    for r in R:
        RC[r] += 1

    bit = BIT(N+1)
    bit.init(RC)

    ans = 0
    for g, gc in GC.items():
        for b, bc in BC.items():
            x = min(N, max(g, b))
            y = min(N, g+b)
            ans += max(0, bit.sum(x, y))*gc*bc
    print(ans)

if __name__ == '__main__':
    main()
0