結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
59,208 KB
testcase_01 AC 39 ms
59,208 KB
testcase_02 AC 42 ms
59,848 KB
testcase_03 AC 111 ms
83,584 KB
testcase_04 AC 105 ms
84,024 KB
testcase_05 AC 103 ms
83,832 KB
testcase_06 AC 97 ms
79,036 KB
testcase_07 AC 90 ms
78,180 KB
testcase_08 AC 91 ms
77,820 KB
testcase_09 AC 100 ms
83,920 KB
testcase_10 AC 246 ms
109,996 KB
testcase_11 AC 284 ms
115,636 KB
testcase_12 AC 482 ms
140,416 KB
testcase_13 AC 399 ms
131,524 KB
testcase_14 AC 469 ms
139,712 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 AC 1,930 ms
247,840 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 1,789 ms
249,600 KB
testcase_24 TLE -
testcase_25 AC 1,780 ms
247,784 KB
testcase_26 TLE -
testcase_27 AC 38 ms
59,208 KB
testcase_28 AC 37 ms
53,460 KB
testcase_29 AC 541 ms
105,140 KB
testcase_30 AC 321 ms
88,720 KB
testcase_31 AC 410 ms
89,024 KB
testcase_32 AC 960 ms
273,980 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(19)
dd=[0]*19

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

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