Skip to content

Commit 664351c

Browse files
author
杨世超
committed
Update 1486. 数组异或操作.md
1 parent d616310 commit 664351c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Solutions/1486. 数组异或操作.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535

3636
就变为了计算前 n 项序列的异或值。假设我们定义一个函数 sumXor(x) 用于计算前 n 项数的异或结果,通过观察可得出:
3737

38-
$sumXor(x) = \left\{ \begin{array} \ x, & x = 4i, k \in Z \\ (x-1) \oplus x, & x = 4i+1, k \in Z \\ (x-2) \oplus (x-1) \oplus x, & x = 4i+2, k \in Z \\ (x-3) \oplus (x-2) \oplus (x-3) \oplus x, & x = 4i+3, k \in Z \end{array} \right.$
38+
$sumXor(x) = \left\{ \begin{array} \ x, & x = 4i, k \in Z \cr (x-1) \oplus x, & x = 4i+1, k \in Z \cr (x-2) \oplus (x-1) \oplus x, & x = 4i+2, k \in Z \cr (x-3) \oplus (x-2) \oplus (x-3) \oplus x, & x = 4i+3, k \in Z \end{array} \right.$
3939

4040
继续化简得:
4141

42-
$sumXor(x) = \left\{ \begin{array} \ x, & x = 4i, k \in Z \\ 1, & x = 4i+1, k \in Z \\ x+1, & x = 4i+2, k \in Z \\ 0, & x = 4i+3, k \in Z \end{array} \right.$
42+
$sumXor(x) = \left\{ \begin{array} \ x, & x = 4i, k \in Z \cr 1, & x = 4i+1, k \in Z \cr x+1, & x = 4i+2, k \in Z \cr 0, & x = 4i+3, k \in Z \end{array} \right.$
4343

4444
则最终结果为 $sumXor(s-1) \oplus sumXor(s+n-1) * 2 + e$。
4545

0 commit comments

Comments
 (0)