結果

問題 No.2300 Substring OR Sum
ユーザー sepa38sepa38
提出日時 2023-05-12 21:48:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,075 ms / 2,000 ms
コード長 439 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 259,948 KB
最終ジャッジ日時 2024-05-06 11:36:49
合計ジャッジ時間 10,412 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,096 KB
testcase_01 AC 43 ms
52,224 KB
testcase_02 AC 39 ms
52,480 KB
testcase_03 AC 339 ms
105,696 KB
testcase_04 AC 286 ms
99,212 KB
testcase_05 AC 352 ms
112,140 KB
testcase_06 AC 207 ms
81,408 KB
testcase_07 AC 1,075 ms
251,352 KB
testcase_08 AC 466 ms
129,112 KB
testcase_09 AC 371 ms
113,148 KB
testcase_10 AC 830 ms
208,412 KB
testcase_11 AC 953 ms
229,036 KB
testcase_12 AC 1,058 ms
251,176 KB
testcase_13 AC 346 ms
259,948 KB
testcase_14 AC 152 ms
103,936 KB
testcase_15 AC 488 ms
138,580 KB
testcase_16 AC 841 ms
208,628 KB
testcase_17 AC 1,042 ms
250,604 KB
testcase_18 AC 39 ms
52,224 KB
testcase_19 AC 38 ms
52,096 KB
testcase_20 AC 37 ms
52,096 KB
testcase_21 AC 37 ms
52,096 KB
testcase_22 AC 39 ms
52,096 KB
権限があれば一括ダウンロードができます

ソースコード

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