#P15677. [ICPC 2024 Jakarta R] Xorderable Array

[ICPC 2024 Jakarta R] Xorderable Array

题目描述

You are given an array A A of N N integers: [A1,A2,,AN] [A_1, A_2, \dots, A_N] .

The array A A is (p,q) (p, q) -xorderable if it is possible to rearrange A A such that for each pair (i,j) (i, j) that satisfies 1i<jN 1 \leq i < j \leq N , the following conditions must be satisfied after the rearrangement: AipAjq A_i \oplus p \leq A_j \oplus q and AiqAjp A_i \oplus q \leq A_j \oplus p . The operator \oplus represents the bitwise xor.

You are given another array X X of length M M : [X1,X2,,XM] [X_1, X_2, \dots, X_M] . Calculate the number of pairs (u,v) (u, v) where array A A is (Xu,Xv) (X_u, X_v) -xorderable for 1u<vM 1 \leq u < v \leq M .

输入格式

The first line consists of two integers N N M M ( 2N,M200000) 2 \leq N, M \leq 200\,000) .

The second line consists of N N integers Ai A_i ( 0Ai<230) 0 \leq A_i < 2^{30}) .

The third line consists of M M integers Xu X_u ( 0Xu<230) 0 \leq X_u < 2^{30}) .

输出格式

Output a single integer representing the number of pairs (u,v) (u, v) where array A A is (Xu,Xv) (X_u, X_v) -xorderable for 1u<vM 1 \leq u < v \leq M .

3 4
0 3 0
1 2 1 1
3
5 2
0 7 13 22 24
12 10
1
3 3
0 0 0
1 2 3
0

提示

Explanation for the sample input/output #1

The array A A is (1,1) (1, 1) -xorderable by rearranging the array A A to [0,0,3] [0, 0, 3] .

Explanation for the sample input/output #2

The array A A is (12,10) (12, 10) -xorderable by rearranging the array A A to [13,0,7,24,22] [13, 0, 7, 24, 22] .