#P4060. [Code+#1] 可做题

    ID: 3001 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp递推O2优化枚举,暴力前缀和位运算,按位

[Code+#1] 可做题

Description

qmqmqm wants to give sublinekelzrip a doable problem. So he came up with this: given a non-negative integer sequence aia_i of length nn, you need to compute its prefix XOR bib_i, defined by b1=a1,bi=bi1xorai(i2)b_1=a_1,b_i=b_{i-1}\operatorname{xor}a_i(i \geq 2).

However, due to a bug in the data generator, the sequence aa is very long, and because of insufficient memory, some aia_i were lost; only the elements at mm positions are known. Now qmqmqm asks you to, based on the remaining aia_i, compute the minimum possible value of i=1nbi\sum_{i=1}^n b_i among the bb sequences corresponding to all possible sequences aa consistent with the known entries.

Input Format

The first line contains two non-negative integers n,mn, m, denoting the length of the original sequence aa and the number of remaining known elements.

Then follow mm lines. Each line contains two numbers i,aii, a_i, indicating the position and value of a known element.

Output Format

Output a single integer denoting the minimum possible value.

5 3
4 0
3 7
5 0
7

Hint

Sample Explanation

The known aa sequence is X,X,7,0,0X,X,7,0,0, where XX means the entry is missing. One possible aa is 0,7,7,0,00,7,7,0,0, whose corresponding bb is 0,7,0,0,00,7,0,0,0, and the minimum sum is 77. It can be proven that there is no smaller case.

Test point ID nn mm Known aia_i
11 n=2n=2 m=1m=1 0ai1090\le a_i\le 10^9
22 1n1091\le n\le10^9 m=0m=0 ^
33 1n1051\le n\le10^5 m=nm=n
44 1n51\le n\le5 0mn0\le m\le n 0ai50\le a_i\le 5
55 ^ ^ ^
66 1n1051\le n\le10^5 0ai10\le a_i\le1
77 ^ ^
88 0ai100\le a_i\le10
99 ^
1010
1111 1n1091\le n\le10^9 0mmin{n,105}0\le m\le\min\{n,10^5\} 0ai10\le a_i\le1
1212 ^ ^ ^
1313 0ai100\le a_i\le10
1414 ^
1616 1n1061\le n\le10^6 0ai1090\le a_i\le10^9
1717 ^ ^
1818 1n1091\le n\le10^9
1919 ^
2020

Note that unknown aia_i can exceed the range of the known aia_i.

It is guaranteed that all ii in the input are distinct and satisfy 1in1 \le i \le n.

From CodePlus 2017 November Contest, produced with honor by the Tsinghua University Department of Computer Science and Technology Student Algorithm and Competition Association.

Credit: idea/Lu Zhengrong, problem setter/Lu Zhengrong, tester/He Haotian.

Git Repo: https://git.thusaac.org/publish/CodePlus201711.

Thanks to Tencent for supporting this contest.

Translated by ChatGPT 5