結果
問題 |
No.2300 Substring OR Sum
|
ユーザー |
![]() |
提出日時 | 2023-07-01 17:42:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 385 ms / 2,000 ms |
コード長 | 761 bytes |
コンパイル時間 | 655 ms |
コンパイル使用メモリ | 82,412 KB |
実行使用メモリ | 258,784 KB |
最終ジャッジ日時 | 2024-07-08 03:42:19 |
合計ジャッジ時間 | 6,461 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
# ビット演算なのでビット桁ごとに計算 # 各桁で0が連続している時だけ数えない、あとは、2**d分だけ数える N = int(input()) A = list(map(int, input().split())) ans = 0 for d in range(30): # increase to 30 zeroone = [] for a in A: if a>>d & 1 == 1: zeroone.append(1) else: zeroone.append(0) zero_len = 0 total = N*(N+1)//2 for i in range(N): if zeroone[i] == 0: zero_len += 1 else: deduct = zero_len*(zero_len+1)//2 total -= deduct zero_len = 0 deduct = zero_len*(zero_len+1)//2 total -= deduct calc = pow(2, d)*total ans += calc #print('d', d, zeroone, total, calc) print(ans)