結果

問題 No.1142 XOR と XOR
コンテスト
ユーザー lam6er
提出日時 2025-03-20 21:11:01
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 1,853 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 218 ms
コンパイル使用メモリ 96,116 KB
実行使用メモリ 231,472 KB
最終ジャッジ日時 2026-07-07 13:00:32
合計ジャッジ時間 12,810 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 TLE * 4 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

MOD = 10**9 + 7

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx]); idx +=1
    M = int(input[idx]); idx +=1
    K = int(input[idx]); idx +=1
    a = list(map(int, input[idx:idx+N]))
    idx +=N
    b = list(map(int, input[idx:idx+M]))
    idx +=M
    
    # Compute prefix XOR for a
    pre_a = [0] * (N+1)
    for i in range(1, N+1):
        pre_a[i] = pre_a[i-1] ^ a[i-1]
    
    # Compute prefix XOR for b
    pre_b = [0] * (M+1)
    for i in range(1, M+1):
        pre_b[i] = pre_b[i-1] ^ b[i-1]
    
    # Calculate counter_a
    counter_a = [0] * 1024
    map_a = [0] * 1024
    map_a[pre_a[0]] += 1  # pre_a[0] =0
    for i in range(1, N+1):
        current = pre_a[i]
        temp_counter = [0] * 1024
        for x in range(1024):
            if map_a[x] == 0:
                continue
            xor_val = current ^ x
            temp_counter[xor_val] += map_a[x]
        # Update counter_a
        for x in range(1024):
            counter_a[x] = (counter_a[x] + temp_counter[x]) % MOD
        # Update map_a
        map_a[current] += 1
    
    # Calculate counter_b
    counter_b = [0] * 1024
    map_b = [0] * 1024
    map_b[pre_b[0]] += 1  # pre_b[0] =0
    for i in range(1, M+1):
        current = pre_b[i]
        temp_counter = [0] * 1024
        for x in range(1024):
            if map_b[x] == 0:
                continue
            xor_val = current ^ x
            temp_counter[xor_val] += map_b[x]
        # Update counter_b
        for x in range(1024):
            counter_b[x] = (counter_b[x] + temp_counter[x]) % MOD
        # Update map_b
        map_b[current] += 1
    
    # Calculate the answer
    ans = 0
    for x in range(1024):
        y = x ^ K
        ans = (ans + counter_a[x] * counter_b[y]) % MOD
    print(ans % MOD)

if __name__ == '__main__':
    main()
0