DMOPC '18 Contest 5 P6 - An XOR Problem

View as PDF

Submit solution


Points: 25 (partial)
Time limit: 2.5s
Memory limit: 256M

Author:
Problem type

A graph has N nodes labelled from 1 to N where node i is assigned a K-bit integer xi. Every pair of nodes (i,j) has an edge between them with weight xixj where denotes the XOR operation. You want to know the total weight of this graph's minimum spanning tree. However, the values assigned to each node sometimes change. In particular, you will receive Q updates of the form c. For each update, xi is changed to (xi+c)mod2K for every i=1,2,,N. After each update, output the weight of the minimum spanning tree.

Constraints

For all subtasks:

0xi,c2K1

1N,Q20000

Subtask 1 [20%]

1K7

Subtask 2 [20%]

1K14

1Q20

Subtask 3 [20%]

6K14

c is divisible by 25 for every update.

Subtask 4 [40%]

1K14

Input Specification

The first line will contain two space-separated integers, N and K.
The second line will contain N space-separated integers, x1,x2,,xN.
The third line will contain a single integer, Q.
The next Q lines will each contain a single integer, c.

Output Specification

Output the weight of the minimum spanning tree after each of the Q updates.

Sample Input

Copy
3 2
1 2 3
2
1
1

Sample Output

Copy
3
3

Explanation for Sample

After the first update, the x values are 0,2,3. Then the minimum total weight is (02)+(23)=3. After the second update, the x values are 0,1,3. The minimum total weight is (01)+(13)=3.


Comments

There are no comments at the moment.