luogu#P9595. 「Daily OI Round 1」Xor

    ID: 9067 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树洛谷原创O2优化分治位运算

「Daily OI Round 1」Xor

Problem Description

Given a sequence of length nn, there are qq queries. In each query, a positive integer xx is given, and the following operations are performed in order:

  • XOR every number in the sequence with xx.
  • Find the longest interval [l,r][l,r] (l,rl,r are non-negative integers) such that every integer in the interval appears in the sequence. The length of the interval is defined as rl+1r-l+1.

Note that after each query, the sequence is modified.

Some clarifications:

  1. “Interval” refers to an interval of integers. For example, the integers in interval [1,3][1,3] are 1,2,31,2,3, and this is unrelated to the sequence.
  2. “Sequence” refers to the modified sequence after applying the current query, and does not include any previous versions of the sequence.

Input Format

The first line contains two positive integers n,qn,q, representing the sequence length and the number of queries.

The second line contains nn positive integers aia_i, representing the initial sequence.

The next qq lines each contain one positive integer xx, representing a query.

Output Format

Output qq lines, one integer per line, representing the answer to each query.

5 2
1 2 3 4 5
1
1

4
5
10 10
5 9 8 3 5 7 10 19 5 24
10
56
19
14
18
53
52
57
96
1000
2
2
2
4
2
3
3
2
2
2

Hint

Sample Explanation

For the first sample, the initial sequence is {1,2,3,4,5}\{1,2,3,4,5\}. In the first query, x=1x=1, so after XOR the sequence becomes {0,3,2,5,4}\{0,3,2,5,4\}. Every integer 2,3,4,52,3,4,5 in the interval [2,5][2,5] appears in this sequence. This is the largest interval that satisfies the condition, so the answer is 52+1=45-2+1=4.

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} Score n,qn,q\leq aia_i\leq xx\leq
00 1010 10310^3 10310^3 10310^3
11 2020 5×1055\times10^5
22 1010 5×1055\times10^5
33 6060 5×1055\times10^5

For all data, it is guaranteed that 1n,q,ai,x5×1051\leq n,q,a_i,x\leq 5\times10^5.

Translated by ChatGPT 5