#P6466. Online Successor XOR Query

    ID: 19680 Type: Default 1000ms 256MiB

Online Successor XOR Query

Online Successor XOR Query

You are given \(k\) sorted arrays, each containing \(n\) integers. You need to answer \(q\) online queries. In each query, you are given an integer \(x\). For each array, find the smallest number that is greater than or equal to \(x\) (i.e. the non-strict successor). If such a number does not exist in an array, consider the answer for that array to be \(0\). The answer to the query is defined as the XOR of these \(k\) numbers.

Additionally, you are given an integer \(d\). You are only required to output the answers of the queries whose 1-indexed query number is a multiple of \(d\>.

Note: You must process the queries online.

inputFormat

The first line contains four space-separated integers \(k\), \(n\), \(q\), and \(d\).

Then follow \(k\) lines, each containing \(n\) space-separated integers representing the sorted arrays.

Then follow \(q\) lines, each containing one integer \(x\), representing a query.

outputFormat

For each query whose index (starting from 1) is a multiple of \(d\), output the XOR value of the successors on a new line.

sample

2 3 4 2
1 3 5
2 4 6
3
1
5
7
3

0

</p>