Sequence and Queries 11

Time limit2sMemory limit512 MB

Summary
Given an array and integer K, answer queries counting subarrays within [l, r] whose XOR equals K.
Level

Hard8 of 10

Topics
Prefix sum, Hash map, Divide and conquer, Binary search
Solved
No attempts yet

Problem

You are given a sequence A1,A2,…,ANA_1, A_2, \ldots, A_N of length NN and an integer KK. Write a program that processes the following query.

  • l r: print the number of pairs (i,j)(i, j) with l≤i≤j≤rl \le i \le j \le r such that the XOR of Ai,Ai+1,…,AjA_i, A_{i+1}, \ldots, A_j is KK.

Input

The first line contains the length of the sequence NN (1≤N≤100,0001 \le N \le 100{,}000) and KK (0≤K≤1,000,0000 \le K \le 1{,}000{,}000).

The second line contains A1,A2,…,ANA_1, A_2, \ldots, A_N (0≤Ai≤1,000,0000 \le A_i \le 1{,}000{,}000).

The third line contains the number of queries MM (1≤M≤100,0001 \le M \le 100{,}000).

Each of the next MM lines contains one query ll, rr (1≤l≤r≤N1 \le l \le r \le N).

Output

For each query, print the answer on its own line.

Examples2

  1. Example 1

    Input
    6 3
    1 2 1 1 0 3
    2
    1 6
    3 5
    
    Expected output
    7
    0
    
  2. Example 2

    Input
    5 1
    1 1 1 1 1
    3
    1 5
    2 4
    1 3
    
    Expected output
    9
    4
    4