結果

問題 No.2300 Substring OR Sum
ユーザー kyskys
提出日時 2023-05-13 16:55:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 1,325 bytes
コンパイル時間 1,330 ms
コンパイル使用メモリ 86,784 KB
実行使用メモリ 259,168 KB
最終ジャッジ日時 2023-08-19 15:25:59
合計ジャッジ時間 7,434 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
71,028 KB
testcase_01 AC 66 ms
71,312 KB
testcase_02 AC 63 ms
71,256 KB
testcase_03 AC 167 ms
105,800 KB
testcase_04 AC 150 ms
102,588 KB
testcase_05 AC 179 ms
111,444 KB
testcase_06 AC 117 ms
87,708 KB
testcase_07 AC 413 ms
203,384 KB
testcase_08 AC 210 ms
126,348 KB
testcase_09 AC 185 ms
112,300 KB
testcase_10 AC 338 ms
170,576 KB
testcase_11 AC 384 ms
203,176 KB
testcase_12 AC 417 ms
200,972 KB
testcase_13 AC 282 ms
259,168 KB
testcase_14 AC 291 ms
258,924 KB
testcase_15 AC 220 ms
128,784 KB
testcase_16 AC 347 ms
176,336 KB
testcase_17 AC 407 ms
201,148 KB
testcase_18 AC 61 ms
71,284 KB
testcase_19 AC 64 ms
71,200 KB
testcase_20 AC 63 ms
71,424 KB
testcase_21 AC 64 ms
71,396 KB
testcase_22 AC 62 ms
71,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    from sys import stdin, setrecursionlimit
    # setrecursionlimit(1000000)
    input = stdin.readline
    def iinput(): return int(input())
    def sinput(): return input().rstrip()
    def i0input(): return int(input()) - 1
    def linput(): return list(input().split())
    def liinput(): return list(map(int, input().split()))
    def miinput(): return map(int, input().split())
    def li0input(): return list(map(lambda x: int(x) - 1, input().split()))
    def mi0input(): return map(lambda x: int(x) - 1, input().split())
    INF = 1000000000000000000
    MOD = 1000000007

    N = iinput()
    A = liinput()

    def rle(s):
        tmp, count, ans1, ans2 = s[0], 1, [], []
        for i in range(1,len(s)):
            if tmp == s[i]:
                count += 1
            else:
                ans1.append(tmp)
                ans2.append(count)
                tmp = s[i]
                count = 1
        ans1.append(tmp)
        ans2.append(count)
        return ans1, ans2

    ans = 0

    for b in range(28):
        bis = []
        for a in A:
            bis.append((a >> b) & 1)
        res = N * (N + 1) // 2
        B, C = rle(bis)
        for bb, cc in zip(B, C):
            if bb == 0:
                res -= cc * (cc + 1) // 2
        ans += (1 << b) * res
    
    print(ans)

main()
0