結果
問題 | No.1863 Xor Sum 2...? |
ユーザー |
![]() |
提出日時 | 2025-03-26 15:57:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 127 ms / 2,000 ms |
コード長 | 1,693 bytes |
コンパイル時間 | 259 ms |
コンパイル使用メモリ | 82,092 KB |
実行使用メモリ | 116,508 KB |
最終ジャッジ日時 | 2025-03-26 15:58:59 |
合計ジャッジ時間 | 4,545 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
import sysfrom collections import defaultdictdef main():input = sys.stdin.read().split()ptr = 0N = int(input[ptr])ptr += 1A = list(map(int, input[ptr:ptr+N]))ptr += NB = list(map(int, input[ptr:ptr+N]))ptr += N# Compute prefix_xor for Bpb = [0] * (N + 1)for i in range(N):pb[i + 1] = pb[i] ^ B[i]# Variables for sum equals xor sliding windowbitmask = 0left_current_sum_xor = 0# Variables for frequency map of pb[l] where l is in the current windowcurrent_freq_left = 0current_freq_right = -1freq = defaultdict(int)total = 0for right in range(N):# Update sum equals xor windowa_val = A[right]while left_current_sum_xor <= right and (bitmask & a_val) != 0:bitmask ^= A[left_current_sum_xor]left_current_sum_xor += 1bitmask |= a_valnew_left_current = left_current_sum_xor# Adjust the frequency window [new_left_current, right]# Remove elements from the left if current_freq_left is behind new_left_currentwhile current_freq_left < new_left_current:val = pb[current_freq_left]freq[val] -= 1if freq[val] == 0:del freq[val]current_freq_left += 1# Add elements to the rightwhile current_freq_right < right:current_freq_right += 1val = pb[current_freq_right]freq[val] += 1# Calculate the target valuetarget = pb[right + 1]count = freq.get(target, 0)total += countprint(total)if __name__ == '__main__':main()