#P11016. XOR Pairs

XOR Pairs

Background

Every day, CT only hums the blues in London and wanders around in front of the school leaders. This lazy and carefree life makes him very down, so he decides to turn over a new leaf and study mathematics.

Problem Description

CT is working on a math problem.

CT has a sequence aa of length nn. Now qq operations are given. For each operation:

  • Change axa_x to yy.
  • After the modification, find the number of valid ordered pairs in the array.

Note: For a pair (ai,aj)(a_i, a_j) with i<ji < j that satisfies aiaj>max{ai,aj}a_i \oplus a_j > \max\{a_i, a_j\}, we call it a valid pair. Here \oplus denotes bitwise XOR, and max{x,y}\max\{x, y\} denotes the larger one of xx and yy.

Input Format

The first line contains two integers n,qn, q.

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

The next qq lines each contain two integers x,yx, y, representing an operation that changes axa_x to yy.

Output Format

For each operation:

Output one integer representing the required answer.

6 4
1 1 4 5 1 4
1 2
4 3
5 2
6 5
9
10
10
9

Hint

Constraints

For all testdata, it is guaranteed that 1n1061 \le n \le 10^6, 1q1051 \le q \le 10^5, 1ai1061 \le a_i \le 10^6, 1xn1 \le x \le n, 1y1061 \le y \le 10^6.

Subtask\text{Subtask} nn\leq qq\leq Score Special Properties
00 10210^2 1313 None
11 10610^6 10510^5 8787

Translated by ChatGPT 5