CSDN话题挑战赛第2期
参赛话题:学习笔记
a^b = x ==> abx = x^x ==> abx = 0 ==> abx^b = 0^b ==> a^x = ba^b = x ==> abx = x^x ==> abx = 0 ==> abx^b = 0^b ==> a^x = b
对于与a配对的数即为ax对于与a配对的数即为ax
Python带默认值的字典(Hash表)为defaultdictPython带默认值的字典(Hash表)为defaultdict
from collections import defaultdict
N = 100010
a = [0] * N
dp = [0] * N
n,m,x = (map(int,input().split()))
a[1:n+1] = list(map(int,input().split()))
last = defaultdict(int)
for i in range(1,n+1):
last[a[i]] = i
dp[i] = max(dp[i-1],last[x^a[i]])
for i in range(m):
l,r = (map(int,input().split()))
if dp[r] >= l:
print(“yes”)
else:
print(“no”)
初始化的时候设定默认值(defaultdict 或 dict.fromkeys)
from collections import defaultdict
aa = defaultdict(int)
aa[‘a’] = 1
aa[‘b’] = 2
aa
defaultdict(<class ‘int’>, {‘a’: 1, ‘b’: 2})
aa[‘c’]
0
aa
defaultdict(<class ‘int’>, {‘a’: 1, ‘b’: 2, ‘c’: 0})
aa = dict.fromkeys(‘abc’, 0)
aa
{‘a’: 0, ‘b’: 0, ‘c’: 0}
aa = defaultdict(lambda : 1)
aa[‘a’]
1