結果

問題 No.1240 Or Sum of Xor Pair
ユーザー onakasuitacity
提出日時 2020-10-25 00:04:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,851 ms / 2,000 ms
コード長 847 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 82,536 KB
実行使用メモリ 260,928 KB
最終ジャッジ日時 2024-07-21 16:11:53
合計ジャッジ時間 52,277 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

def _fourier(f, inverse = False):
    f = f[:]
    n = (len(f) - 1).bit_length()
    for d in range(n):
        for U in range(1 << n):
            if not U >> d & 1:
                s, t = f[U], f[U | 1 << d]
                f[U], f[U | 1 << d] = s + t, s - t
    if inverse:
        for U in range(1 << n):
            f[U] >>= n
    return f

def convolution(f, g):
    return _fourier([a * b for a, b in zip(_fourier(f), _fourier(g))], inverse = 1)

n, x = map(int, input().split())
A = list(map(int, input().split()))
m = max(A).bit_length()

f = [0] * (1 << m)
g = [0] * (1 << m)
for a in A:
    f[a] += a
    g[a] += 1
fg = convolution(f, g)
ans = 2 * sum(fg[:x])

for d in range(m):
    f = [0] * (1 << m)
    for a in A:
        f[a] += a >> d & 1
    f2 = convolution(f, f)
    ans -= sum(f2[:x]) << d

ans -= sum(A)
ans //= 2
print(ans)
0