아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

XOR Pairs

시간 제한1초메모리 제한1024 MB

요약
A, B가 각각 A xor B 이하이고, xor 값이 N 이하이며 S에 속하지 않는 순서쌍 (A, B)의 개수를 센다.
난이도

보통10점 중 7점

유형
수학, 비트 연산, 조합론, 동적 계획법
정답자
아직 제출이 없습니다

문제

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 ⊕, or in most programming languages, the character ^(caret). For example, (10 ⊕ 6) = 12.

10 =>  1010
 6 =>  0110
      ----- ⊕
       1100   => 12

In this problem, you are given an integer N and a set of integers S1..M. Your task is to count how many pairs of integers <A, B> such that 1 ≤ A, B ≤ (A ⊕ B) ≤ N, and (A ⊕ B) ∉ S.

For example, let N = 10 and S1..4 = {4, 6, 7, 10}. There are 6 pairs of <A, B> that satisfy the condition.

  • <1, 2> → (1 ⊕ 2) = 3
  • <1, 4> → (1 ⊕ 4) = 5
  • <1, 8> → (1 ⊕ 8) = 9
  • <2, 1> → (2 ⊕ 1) = 3
  • <4, 1> → (4 ⊕ 1) = 5
  • <8, 1> → (8 ⊕ 1) = 9

Observe that a pair such as <2, 4> does not satisfy the condition for this example as (2 ⊕ 4) = 6 but 6 ∈ S. Another pair such as <5, 1> also does not satisfy the condition as it violates the requirement A, B ≤ (A ⊕ B).

입력

Input begins with a line containing two integers N M (1 ≤ N ≤ 106; 1 ≤ M ≤ 100 000) representing the given N and the size of the set of integers S1..M. The next line contains M integers Si (1 ≤ Si ≤ 106) representing the set of integers S1..M.

출력

Output contains an integer in a line representing the number of <A, B> such that 1 ≤ A, B ≤ (A ⊕ B) ≤ N and (A ⊕ B) ∉ S1..M.

예제4

  1. 예제 1

    입력
    10 4
    4 6 7 10
    
    예상 출력
    6
    
  2. 예제 2

    입력
    8 5
    4 3 5 8 1
    
    예상 출력
    10
    
  3. 예제 3

    입력
    20 7
    3 7 18 15 12 18 19
    
    예상 출력
    50
    
  4. 예제 4

    입력
    5 6
    1 2 3 4 5 6
    
    예상 출력
    0