#P15603. [ICPC 2021 Jakarta R] XOR Pairs

[ICPC 2021 Jakarta R] XOR Pairs

题目描述

XOR is a bitwise operator that evaluates the resulting bit into 1 if and only if their corresponding input bits differ (one of them is 1 while the other is 0). XOR operator is usually written with a symbol \oplus, or in most programming languages, the character ^ (caret). For example, (106)=12(10 \oplus 6) = 12.

$$\begin{aligned} 10\ &=>\ \ \ 1010 \\ 6\ &=>\ \ \ 0110 \\ \quad\ &----\ \oplus \\ \quad\ & \quad \quad \quad 1100\ \ =>\ 12 \\ \end{aligned} $$

In this problem, you are given an integer NN and a set of integers S1..MS_{1..M}. Your task is to count how many pairs of integers A,B\langle A, B \rangle such that 1A,B(AB)N1 \leq A, B \leq (A \oplus B) \leq N, and (AB)S(A \oplus B) \notin S.

For example, let N=10N = 10 and S1..4={4,6,7,10}S_{1..4} = \{4, 6, 7, 10\}. There are 6 pairs of A,B\langle A, B \rangle that satisfy the condition.

  • 1,2(12)=3\langle 1, 2 \rangle \rightarrow (1 \oplus 2) = 3
  • 1,4(14)=5\langle 1, 4 \rangle \rightarrow (1 \oplus 4) = 5
  • 1,8(18)=9\langle 1, 8 \rangle \rightarrow (1 \oplus 8) = 9
  • 2,1(21)=3\langle 2, 1 \rangle \rightarrow (2 \oplus 1) = 3
  • 4,1(41)=5\langle 4, 1 \rangle \rightarrow (4 \oplus 1) = 5
  • 8,1(81)=9\langle 8, 1 \rangle \rightarrow (8 \oplus 1) = 9

Observe that a pair such as 2,4\langle 2, 4 \rangle does not satisfy the condition for this example as (24)=6(2 \oplus 4) = 6 but 6S6 \in S. Another pair such as 5,1\langle 5, 1 \rangle also does not satisfy the condition as it violates the requirement A,B(AB)A, B \leq (A \oplus B).

输入格式

Input begins with a line containing two integers NN MM (1N1061 \leq N \leq 10^6; 1M1000001 \leq M \leq 100\,000) representing the given NN and the size of the set of integers S1..MS_{1..M}. The next line contains MM integers SiS_i (1Si1061 \leq S_i \leq 10^6) representing the set of integers S1..MS_{1..M}.

输出格式

Output contains an integer in a line representing the number of A,B\langle A, B \rangle such that 1A,B(AB)N1 \leq A, B \leq (A \oplus B) \leq N and (AB)S1..M(A \oplus B) \notin S_{1..M}.

10 4
4 6 7 10
6
8 5
4 3 5 8 1
10
20 7
3 7 18 15 12 18 19
50
5 6
1 2 3 4 5 6
0

提示

Explanation for the sample input/output #1

This is the example from the problem description.

Explanation for the sample input/output #2

There are 10 pairs of A,B\langle A, B \rangle that satisfy the condition.

  • 1,6(16)=7\langle 1, 6 \rangle \rightarrow (1 \oplus 6) = 7
  • 2,4(24)=6\langle 2, 4 \rangle \rightarrow (2 \oplus 4) = 6
  • 2,5(25)=7\langle 2, 5 \rangle \rightarrow (2 \oplus 5) = 7
  • 3,4(34)=7\langle 3, 4 \rangle \rightarrow (3 \oplus 4) = 7
  • 3,5(35)=6\langle 3, 5 \rangle \rightarrow (3 \oplus 5) = 6
  • 4,2(42)=6\langle 4, 2 \rangle \rightarrow (4 \oplus 2) = 6
  • 4,3(43)=7\langle 4, 3 \rangle \rightarrow (4 \oplus 3) = 7
  • 5,2(52)=7\langle 5, 2 \rangle \rightarrow (5 \oplus 2) = 7
  • 5,3(53)=6\langle 5, 3 \rangle \rightarrow (5 \oplus 3) = 6
  • 6,1(61)=7\langle 6, 1 \rangle \rightarrow (6 \oplus 1) = 7