結果
| 問題 |
No.1142 XOR と XOR
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 23:46:59 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 128 ms / 2,000 ms |
| コード長 | 1,310 bytes |
| コンパイル時間 | 142 ms |
| コンパイル使用メモリ | 82,172 KB |
| 実行使用メモリ | 114,400 KB |
| 最終ジャッジ日時 | 2025-04-15 23:49:12 |
| 合計ジャッジ時間 | 3,863 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
MOD = 10**9 + 7
def fwht_xor(a, invert):
n = len(a)
h = 1
while h < n:
for i in range(0, n, h * 2):
for j in range(i, i + h):
x = a[j]
y = a[j + h]
a[j] = (x + y) % MOD
a[j + h] = (x - y) % MOD
if invert:
a[j] = a[j] * 500000004 % MOD # Modular inverse of 2
a[j + h] = a[j + h] * 500000004 % MOD
h *= 2
def compute_counts(arr):
F = [0] * 1024
F[0] = 1 # Initial prefix XOR of 0
pre = 0
for num in arr:
pre ^= num
F[pre] = (F[pre] + 1) % MOD
sum_F = sum(F) % MOD
a = F.copy()
fwht_xor(a, False)
for i in range(1024):
a[i] = a[i] * a[i] % MOD
fwht_xor(a, True)
count = [0] * 1024
inv_2 = 500000004 # Precomputed inverse of 2 mod MOD
for x in range(1024):
if x == 0:
count[x] = (a[x] - sum_F) * inv_2 % MOD
else:
count[x] = a[x] * inv_2 % MOD
return count
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count_a = compute_counts(a)
count_b = compute_counts(b)
ans = 0
for x in range(1024):
y = x ^ K
ans = (ans + count_a[x] * count_b[y]) % MOD
print(ans % MOD)
lam6er