結果

問題 No.2300 Substring OR Sum
ユーザー sepa38
提出日時 2023-05-12 21:48:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,136 ms / 2,000 ms
コード長 439 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 259,908 KB
最終ジャッジ日時 2024-11-28 17:54:22
合計ジャッジ時間 10,722 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
n = int(input())
a = list(map(int, input().split()))
k = 28
ls = [[] for _ in range(k)]
for i in range(n):
  for j in range(k):
    if a[i] & (1 << j):
      ls[j].append(i)
ans = 0
for i in range(n):
  for j in range(k):
    if a[i] & (1 << j):
      ans += (n - i) * (1 << j)
      continue
    else:
      idx = bisect.bisect_right(ls[j], i)
      if idx < len(ls[j]):
        ans += (n - ls[j][idx]) * (1 << j)
print(ans)
0