結果

問題 No.1240 Or Sum of Xor Pair
ユーザー mkawa2mkawa2
提出日時 2023-11-28 00:05:37
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,106 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 270,320 KB
最終ジャッジ日時 2023-11-28 00:06:13
合計ジャッジ時間 18,224 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
59,208 KB
testcase_01 AC 42 ms
59,208 KB
testcase_02 AC 43 ms
59,848 KB
testcase_03 AC 117 ms
83,176 KB
testcase_04 AC 114 ms
83,728 KB
testcase_05 AC 113 ms
83,736 KB
testcase_06 AC 101 ms
79,048 KB
testcase_07 AC 96 ms
78,172 KB
testcase_08 AC 101 ms
77,908 KB
testcase_09 AC 112 ms
83,536 KB
testcase_10 AC 304 ms
109,372 KB
testcase_11 AC 358 ms
116,448 KB
testcase_12 AC 504 ms
136,428 KB
testcase_13 AC 479 ms
129,168 KB
testcase_14 AC 592 ms
141,224 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 1,991 ms
244,152 KB
testcase_24 TLE -
testcase_25 AC 1,922 ms
244,628 KB
testcase_26 TLE -
testcase_27 AC 41 ms
59,208 KB
testcase_28 AC 38 ms
53,460 KB
testcase_29 WA -
testcase_30 AC 314 ms
88,592 KB
testcase_31 AC 372 ms
89,024 KB
testcase_32 AC 999 ms
270,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 63)
# md = 10**9+7
md = 998244353

class BinaryTrie:
    def __init__(self, max_bit_len=32):
        self.dd=[[0]*max_bit_len]
        self.cc = [0]
        self.to = [[-1], [-1]]
        self.mb = max_bit_len

    def add(self, a):
        u = 0
        self.cc[u] += 1
        for i in range(self.mb-1, -1, -1):
            d = a >> i & 1
            if self.to[d][u] == -1:
                self.to[d][u] = len(self.cc)
                self.to[0].append(-1)
                self.to[1].append(-1)
                self.cc.append(0)
                self.dd.append([0]*self.mb)
            u = self.to[d][u]
            self.cc[u] += 1
            dd=self.dd[u]
            for j in range(self.mb):dd[j]+=a>>j&1

    def getval(self,a,x):
        res=[0]*self.mb
        ax=a^x
        u=0
        for i in range(self.mb)[::-1]:
            e=ax>>i&1
            v=self.to[e^1][u]
            if x>>i&1 and v!=-1:
                for j in range(self.mb):
                    if a>>j&1:
                        res[j]+=self.cc[v]
                    else:
                        res[j]+=self.dd[v][j]
            u=self.to[e][u]
            if u==-1:break
        return res

n,x=LI()
aa=LI()
bt=BinaryTrie(18)
dd=[0]*18

for a in aa:
    res=bt.getval(a,x)
    for j in range(18):dd[j]+=res[j]
    bt.add(a)

ans=0
base=1
for d in dd:
    ans+=base*d
    base<<=1
print(ans)
0