結果

問題 No.2300 Substring OR Sum
ユーザー kyskys
提出日時 2023-05-13 16:55:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 1,325 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 82,452 KB
実行使用メモリ 258,268 KB
最終ジャッジ日時 2024-05-06 22:31:26
合計ジャッジ時間 5,856 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
52,352 KB
testcase_01 AC 39 ms
52,480 KB
testcase_02 AC 40 ms
52,224 KB
testcase_03 AC 164 ms
105,456 KB
testcase_04 AC 140 ms
102,752 KB
testcase_05 AC 173 ms
111,120 KB
testcase_06 AC 108 ms
85,992 KB
testcase_07 AC 415 ms
197,972 KB
testcase_08 AC 198 ms
122,084 KB
testcase_09 AC 163 ms
109,916 KB
testcase_10 AC 336 ms
176,584 KB
testcase_11 AC 375 ms
186,968 KB
testcase_12 AC 417 ms
194,944 KB
testcase_13 AC 299 ms
258,268 KB
testcase_14 AC 306 ms
257,800 KB
testcase_15 AC 220 ms
127,324 KB
testcase_16 AC 366 ms
181,496 KB
testcase_17 AC 422 ms
198,392 KB
testcase_18 AC 39 ms
52,224 KB
testcase_19 AC 37 ms
51,968 KB
testcase_20 AC 38 ms
52,480 KB
testcase_21 AC 38 ms
52,224 KB
testcase_22 AC 37 ms
51,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    from sys import stdin, setrecursionlimit
    # setrecursionlimit(1000000)
    input = stdin.readline
    def iinput(): return int(input())
    def sinput(): return input().rstrip()
    def i0input(): return int(input()) - 1
    def linput(): return list(input().split())
    def liinput(): return list(map(int, input().split()))
    def miinput(): return map(int, input().split())
    def li0input(): return list(map(lambda x: int(x) - 1, input().split()))
    def mi0input(): return map(lambda x: int(x) - 1, input().split())
    INF = 1000000000000000000
    MOD = 1000000007

    N = iinput()
    A = liinput()

    def rle(s):
        tmp, count, ans1, ans2 = s[0], 1, [], []
        for i in range(1,len(s)):
            if tmp == s[i]:
                count += 1
            else:
                ans1.append(tmp)
                ans2.append(count)
                tmp = s[i]
                count = 1
        ans1.append(tmp)
        ans2.append(count)
        return ans1, ans2

    ans = 0

    for b in range(28):
        bis = []
        for a in A:
            bis.append((a >> b) & 1)
        res = N * (N + 1) // 2
        B, C = rle(bis)
        for bb, cc in zip(B, C):
            if bb == 0:
                res -= cc * (cc + 1) // 2
        ans += (1 << b) * res
    
    print(ans)

main()
0