結果

問題 No.2300 Substring OR Sum
ユーザー kys
提出日時 2023-05-13 16:55:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 420 ms / 2,000 ms
コード長 1,325 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 82,844 KB
実行使用メモリ 258,780 KB
最終ジャッジ日時 2024-11-29 08:54:23
合計ジャッジ時間 6,526 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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