Xorderable Array

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

요약
u<v인 쌍 (X_u, X_v) 가운데, A를 재배열해 앞 원소를 p, q로 각각 xor한 값이 뒤 원소의 xor 값 이하가 되도록 만들 수 있는 쌍의 개수를 센다.
난이도

어려움10점 중 8점

유형
비트 연산, 정렬, 트라이, 조합론
정답자
아직 제출이 없습니다

문제

You are given an array AA of NN integers: \[A_1,A_2,…,A_N]\[A\_1, A\_2, \dots , A\_N ].

The array AA is (p,q)(p, q)-xorderable if it is possible to rearrange AA such that for each pair (i,j)(i, j) that satisfies 1≤i<j≤N1 ≤ i < j ≤ N, the following conditions must be satisfied after the rearrangement: A_i⊕p≤A_j⊕qA\_i \oplus p ≤ A\_j \oplus q and A_i⊕q≤A_j⊕pA\_i \oplus q ≤ A\_j \oplus p. The operator ⊕\oplus represents the bitwise xor.

You are given another array XX of length MM: \[X_1,X_2,…,X_M]\[X\_1, X\_2, \dots , X\_M]. Calculate the number of pairs (u,v)(u, v) where array AA is (X_u,X_v)(X\_u, X\_v)-xorderable for 1≤u<v≤M1 ≤ u < v ≤ M.

입력

The first line consists of two integers NN MM (2≤N,M≤200,0002 ≤ N, M ≤ 200\\, 000).

The second line consists of NN integers A_iA\_i (0≤A_i<2300 ≤ A\_i < 2^{30}).

The third line consists of MM integers X_uX\_u (0≤X_u<2300 ≤ X\_u < 2^{30}).

출력

Output a single integer representing the number of pairs (u,v)(u, v) where array AA is (X_u,X_v)(X\_u, X\_v)-xorderable for 1≤u<v≤M1 ≤ u < v ≤ M.

예제3

  1. 예제 1

    입력
    3 4
    0 3 0
    1 2 1 1
    
    예상 출력
    3
    
  2. 예제 2

    입력
    5 2
    0 7 13 22 24
    12 10
    
    예상 출력
    1
    
  3. 예제 3

    입력
    3 3
    0 0 0
    1 2 3
    
    예상 출력
    0