Kth largest element

1

1 votes
Problem

 You are given an array A of length N and an integer K.


   A function F(i,j) is defined below as, 
    F(i,j) = ai ^ ai+1 ^ ai+2 ^... ^aj .
   where ai , ai+1 , .. , aj  are elements of array A and 0 <= i <= j < n .   

  •    Symbol ^ is Exclusive Or

 You use the above function F(i,j) for each unique pair (i, j) , where 0 <= i < n and 0 <= j < n and i <= j ,  and put the results into a new  array B.

   Your task is to find the Kth largest element of array B.

   Note : Assume K is always valid and answer always exists for given K.

 

Input :

  • The first line contains two numbers and K .
  • The second line contains numbers - a1,a2,a3,…,aN .

Output :

  • Output  the Kth largest element of array B .

Constraint :

  • 1 <= N <= 105
  • 0 <= a<= 106
  • K >= 1 and  is always valid .


 

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

valid (i,j) are {(0,0),(0,1),(0,2),(1,1),(1,2),(2,2)}

on applying F(i,j) for each (i,j), we get an array B as {4,2,0,6,4,2}.

Therefore , 4th largest element of B is 2.

Editor Image

?