結果
問題 | No.2061 XOR Sort |
ユーザー | 👑 rin204 |
提出日時 | 2022-08-26 22:27:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 934 ms / 2,000 ms |
コード長 | 3,734 bytes |
コンパイル時間 | 369 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 295,344 KB |
最終ジャッジ日時 | 2024-10-13 23:05:12 |
合計ジャッジ時間 | 11,809 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
52,480 KB |
testcase_01 | AC | 42 ms
52,224 KB |
testcase_02 | AC | 41 ms
52,480 KB |
testcase_03 | AC | 45 ms
58,624 KB |
testcase_04 | AC | 39 ms
52,736 KB |
testcase_05 | AC | 44 ms
59,008 KB |
testcase_06 | AC | 47 ms
58,880 KB |
testcase_07 | AC | 44 ms
57,984 KB |
testcase_08 | AC | 40 ms
52,864 KB |
testcase_09 | AC | 44 ms
58,624 KB |
testcase_10 | AC | 40 ms
52,352 KB |
testcase_11 | AC | 42 ms
52,608 KB |
testcase_12 | AC | 47 ms
59,008 KB |
testcase_13 | AC | 40 ms
52,224 KB |
testcase_14 | AC | 389 ms
180,244 KB |
testcase_15 | AC | 393 ms
180,744 KB |
testcase_16 | AC | 934 ms
294,428 KB |
testcase_17 | AC | 499 ms
216,344 KB |
testcase_18 | AC | 477 ms
215,960 KB |
testcase_19 | AC | 474 ms
216,240 KB |
testcase_20 | AC | 122 ms
92,928 KB |
testcase_21 | AC | 232 ms
131,516 KB |
testcase_22 | AC | 402 ms
180,812 KB |
testcase_23 | AC | 73 ms
71,808 KB |
testcase_24 | AC | 923 ms
295,344 KB |
testcase_25 | AC | 916 ms
294,708 KB |
testcase_26 | AC | 924 ms
294,760 KB |
testcase_27 | AC | 921 ms
294,824 KB |
testcase_28 | AC | 929 ms
294,700 KB |
testcase_29 | AC | 169 ms
86,592 KB |
testcase_30 | AC | 38 ms
52,480 KB |
testcase_31 | AC | 87 ms
77,056 KB |
testcase_32 | AC | 53 ms
52,224 KB |
testcase_33 | AC | 39 ms
52,480 KB |
testcase_34 | AC | 40 ms
52,992 KB |
testcase_35 | AC | 39 ms
52,736 KB |
testcase_36 | AC | 39 ms
52,736 KB |
testcase_37 | AC | 40 ms
52,864 KB |
testcase_38 | AC | 41 ms
52,864 KB |
testcase_39 | AC | 42 ms
52,736 KB |
testcase_40 | AC | 41 ms
52,736 KB |
testcase_41 | AC | 40 ms
53,120 KB |
testcase_42 | AC | 40 ms
52,736 KB |
testcase_43 | AC | 40 ms
52,608 KB |
ソースコード
class Binary_Trie_Vertex: def __init__(self): self.left = None self.right = None self.parent = None self.size = 0 class Binary_Trie: def __init__(self, logn, ismulti = False): self.logn = logn self.root = Binary_Trie_Vertex() self.bi = [1 << i for i in range(logn)] self.multi = ismulti self.tf = [False] * logn def add(self, x): V = self.root plus = False for i in range(self.logn - 1, -1, -1): if x >> i & 1: if V.right is None: V.right = Binary_Trie_Vertex() V.right.parent = V plus = True if V.left is not None: self.tf[i] = True V = V.right else: if V.left is None: V.left = Binary_Trie_Vertex() V.left.parent = V plus = True if V.right is not None: self.tf[i] = True V = V.left if plus or self.multi: while V.parent is not None: V.size += 1 V = V.parent V.size += 1 def remove(self, x): V = self.root for i in range(self.logn - 1, -1, -1): if x >> i & 1: if V.right is None: return False V = V.right else: if V.left is None: return False V = V.left V2 = V while V2.parent is not None: V2.size -= 1 V2 = V2.parent V2.size -= 1 while V.size == 0 and V != self.root: P = V.parent if P.right == V: P.right = None else: P.left = None if P.right is None and P.left is None: pass else: return True V = P return True def search(self, x): V = self.root for i in range(self.logn - 1, -1, -1): if x >> i & 1: if V.right is None: return False V = V.right else: if V.left is None: return False V = V.left return True def xor_min(self, x): xor = 0 V = self.root for i in range(self.logn - 1, -1, -1): if x >> i & 1: if V.right is not None: V = V.right else: xor += self.bi[i] V = V.left else: if V.left is not None: V = V.left else: xor += self.bi[i] V = V.right return xor def __getitem__(self, k): return self.Kth_element(k) def Kth_element(self, k): if k < 0: k = self.root.size + k k += 1 if k > self.root.size or k <= 0: return None ret = 0 V = self.root for i in range(self.logn - 1, -1, -1): if V.left is None: ret += self.bi[i] V = V.right elif V.right is None: V = V.left elif V.left.size >= k: V = V.left else: ret += self.bi[i] k -= V.left.size V = V.right return ret MOD = 998244353 n = int(input()) A = list(map(int, input().split())) bt = Binary_Trie(30) for a in A: bt.add(a) c = sum(bt.tf) print(pow(2, c, MOD))