codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

742B.md (2232B)


      1 Source: https://codeforces.com/problemset/problem/742/B
      2 
      3 B. Arpa’s obvious problem and Mehrdad’s terrible solution
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 There are some beautiful girls in Arpa’s land as mentioned before.
     22 
     23 Once Arpa came up with an obvious problem:
     24 
     25 Given an array and a number *x*, count the number of pairs of indices *i*, *j* (1 ≤ *i* < *j* ≤ *n*) such that ![](https://espresso.codeforces.com/e662849e402231f44df5caaa0b73782e1f4023d9.png), where ![](https://espresso.codeforces.com/736746f0b23eaf899b476d924bdc54d2d1b0f6cd.png) is bitwise xor operation (see notes for explanation).
     26 
     27  ![](https://espresso.codeforces.com/dabb26b186836749476e3b172f0e6aef26dcb498.png) 
     28 
     29 Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
     30 
     31 Input
     32 
     33 First line contains two integers *n* and *x* (1 ≤ *n* ≤ 105, 0 ≤ *x* ≤ 105) — the number of elements in the array and the integer *x*.
     34 
     35 Second line contains *n* integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 105) — the elements of the array.
     36 
     37 Output
     38 
     39 Print a single integer: the answer to the problem.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 2 3  
     47 1 2
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 1
     54 ```
     55 
     56 Input
     57 
     58 ```
     59 6 1  
     60 5 1 2 3 4 1
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 2
     67 ```
     68 
     69 Note
     70 
     71 In the first sample there is only one pair of *i* = 1 and *j* = 2. ![](https://espresso.codeforces.com/bec9071ce5b1039982fe0ae476cd31528ddfa2f3.png) so the answer is 1.
     72 
     73 In the second sample the only two pairs are *i* = 3, *j* = 4 (since ![](https://espresso.codeforces.com/3701990d023d19c5da0b315b5057d572ec11e4fd.png)) and *i* = 1, *j* = 5 (since ![](https://espresso.codeforces.com/8c96223ca88621240a5ee6e1498acb7e4ce0eb44.png)).
     74 
     75 A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: <https://en.wikipedia.org/wiki/Bitwise_operation#XOR>.