#P10650. [ROI 2017] 排序幻觉 (Day 1)

    ID: 12150 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心2017O2优化位运算ROI(俄罗斯)

[ROI 2017] 排序幻觉 (Day 1)

Problem Description

Given an integer sequence aa of length nn, if an integer bb satisfies:

$$(a_1 \operatorname{xor} b) \le (a_2 \operatorname{xor} b) \le \dots \le (a_n \operatorname{xor} b)$$

then bb is called a magic number of the sequence aa.

Next, there are qq modifications. In each modification, one number auia_{u_i} is changed to an integer kik_i. Each modification affects the queries that follow. You need to find the smallest magic number of the sequence before the first modification and after each modification. In particular, if no magic number exists, output 1-1.

Input Format

The first line contains an integer nn, indicating the length of the sequence.

The second line contains nn integers, representing the integer sequence aa.

The third line contains an integer qq, indicating the number of queries.

The next qq lines each contain two integers uiu_i and kik_i, meaning that auia_{u_i} is modified to kik_i.

Output Format

Output a total of (q+1)(q + 1) lines. Each line contains one integer, representing the smallest magic number of the current sequence. If there is no magic number, output 1-1.

3
0 1 4
3
2 7
3 3
1 4
0
2
-1
4

Hint

Constraints

Subtask ID Score 1n1 \le n \le 1q1 \le q \le 0ai,ki0 \le a_i, k_i \le
11 3030 500500 292^9
22 2929 10310^3 2302^{30}
33 2121 10510^5
44 3030 10610^6

Translated by ChatGPT 5