PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000067. XOR và con số yêu thích (XOR and Favorite Number)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

XOR và con số yêu thích (XOR and Favorite Number)

XOR and Favorite Number

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a nonnegative array a1,…,ana_1,\ldots,a_n and integer kk, count the index pairs (i,j)(i,j) with l≤i≤j≤rl\le i\le j\le r such that ai⊕⋯⊕aj=ka_i\oplus\cdots\oplus a_j=k, for each inclusive range [l,r][l,r]. Pairs with different indices count separately.

Input

Read n,q,kn,q,k, followed by nn integers and then qq inclusive queries l,rl,r (1-based).

Output

Print one 64-bit count per query in the input order.

Subtasks

  • Subtask 1 (10 points): 1≤n≤501\le n\le 50, 1≤q≤601\le q\le 60. 0≤k,ai≤1060\le k,a_i\le 10^6; 1≤l≤r≤n1\le l\le r\le n.
  • Subtask 2 (20 points): 1≤n≤25001\le n\le 2500, 1≤q≤25001\le q\le 2500. 0≤k,ai≤1060\le k,a_i\le 10^6; 1≤l≤r≤n1\le l\le r\le n.
  • Subtask 3 (30 points): 1≤n≤200001\le n\le 20000, 1≤q≤200001\le q\le 20000. 0≤k,ai≤1060\le k,a_i\le 10^6; 1≤l≤r≤n1\le l\le r\le n.
  • Subtask 4 (40 points): 1≤n≤1000001\le n\le 100000, 1≤q≤1000001\le q\le 100000. 0≤k,ai≤1060\le k,a_i\le 10^6; 1≤l≤r≤n1\le l\le r\le n.

Examples

Input

6 2 3
1 2 1 1 0 3
1 6
3 5

Output

7
0

Explanation

There are 7 valid index pairs in [1,6][1,6], including [1,2][1,2] (XOR 1⊕2=31\oplus2=3) and [6,6][6,6] (value 3). No subarray of [3,5][3,5] has XOR 3.