結果

問題 No.2300 Substring OR Sum
ユーザー qibqib
提出日時 2023-05-15 17:35:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 444 bytes
コンパイル時間 403 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 112,496 KB
最終ジャッジ日時 2023-08-20 18:50:12
合計ジャッジ時間 6,241 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,124 KB
testcase_01 AC 72 ms
71,304 KB
testcase_02 AC 78 ms
71,168 KB
testcase_03 AC 153 ms
84,728 KB
testcase_04 AC 156 ms
83,148 KB
testcase_05 AC 158 ms
85,980 KB
testcase_06 AC 124 ms
80,376 KB
testcase_07 AC 326 ms
111,896 KB
testcase_08 AC 180 ms
88,676 KB
testcase_09 AC 154 ms
86,024 KB
testcase_10 AC 249 ms
101,332 KB
testcase_11 AC 298 ms
110,908 KB
testcase_12 AC 319 ms
111,728 KB
testcase_13 AC 155 ms
100,344 KB
testcase_14 AC 130 ms
104,516 KB
testcase_15 AC 185 ms
90,348 KB
testcase_16 AC 253 ms
101,668 KB
testcase_17 AC 316 ms
112,496 KB
testcase_18 AC 78 ms
71,308 KB
testcase_19 AC 76 ms
71,436 KB
testcase_20 AC 75 ms
71,180 KB
testcase_21 AC 77 ms
71,536 KB
testcase_22 AC 77 ms
71,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))

ans = 0
for d in range(28):
  l = None
  st = []
  for i in range(n):
    if l is None:
      if (a[i] >> d) & 1 == 0:
        l = i
    else:
      if (a[i] >> d) & 1 != 0:
        st.append((l, i - 1))
        l = None

  if not l is None:
    st.append((l, n - 1))

  cnt = n * (n + 1) // 2
  for l, r in st:
    cnt -= (r - l + 1) * (r - l + 2) // 2

  ans += (1 << d) * cnt

print(ans)
0