結果

問題 No.2300 Substring OR Sum
ユーザー lam6er
提出日時 2025-03-20 20:29:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 559 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 82,484 KB
実行使用メモリ 108,132 KB
最終ジャッジ日時 2025-03-20 20:30:05
合計ジャッジ時間 3,221 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))
total_subarrays = n * (n + 1) // 2
result = 0

for k in range(28):  # Process each bit from 0 to 27
    count_zero = 0
    current = 0
    for num in a:
        if (num & (1 << k)) == 0:
            current += 1
        else:
            count_zero += current * (current + 1) // 2
            current = 0
    # Add the last segment of zeros after loop ends
    count_zero += current * (current + 1) // 2
    contribution = (total_subarrays - count_zero) * (1 << k)
    result += contribution

print(result)
0