Counting Inversions Again!

All submissions for this problem are available.
### Read problem statements in [Hindi](http://www.codechef.com/download/translated/LTIME77/hindi/INVZCNT.pdf), [Bengali](http://www.codechef.com/download/translated/LTIME77/bengali/INVZCNT.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/LTIME77/mandarin/INVZCNT.pdf), [Russian](http://www.codechef.com/download/translated/LTIME77/russian/INVZCNT.pdf), and [Vietnamese](http://www.codechef.com/download/translated/LTIME77/vietnamese/INVZCNT.pdf) as well. You are given a sequence of nonnegative integers $A_1, A_2, \ldots, A_N$. A pair $(x, y)$, where $1 \le x \lt y \le N$, is an *inversion* if $A_x \gt A_y$. You should answer $Q$ queries (numbered $1$ through $Q$). For each valid $i$, in the $i$th query:  You are given a nonnegative integer $K_i$.  Consider a sequence $B_1, B_2, \ldots, B_N$, where $B_j = A_j \oplus K$ for each valid $j$.  You should find the number of inversions in the sequence $B$. ### Input  The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.  The first line of each test case contains two spaceseparated integers $N$ and $Q$.  The second line contains $N$ spaceseparated integers $A_1, A_2, \ldots, A_N$.  each of the next $Q$ lines describes a query with a single integer $K_i$. ### Output For each test case, print $Q$ lines. For each valid $i$, the $i$th of these lines should contain a single integer ― the answer to the $i$th query. ### Constraints  $1 \le T \le 10$  $1 \le N, Q \le 10^6$  $0 \le K_i \lt 2^{31}$ for each valid $i$  $0 \le A_i \lt 2^{31}$ for each valid $i$  the sum of $N$ over all test cases does not exceed $10^6$  the sum of $Q$ over all test cases does not exceed $10^6$ ### Subtasks **Subtask #1 (50 points):**  $1 \le Q \le 5$  $1 \le N \le 10^5$  the sum of $N$ over all test cases does not exceed $10^5$  the sum of $Q$ over all test cases does not exceed $5$ **Subtask #2 (50 points):** original constraints ### Example Input ``` 1 4 4 3 1 2 0 0 1 2 3 ``` ### Example Output ``` 5 3 3 1 ```Author:  jafarbadour 
Editorial  https://discuss.codechef.com/problems/INVZCNT 
Tags  jafarbadour, jafarbadour, ltime77 
Date Added:  24102019 
Time Limit:  3 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 