当前位置:网站首页>【学习笔记】线性基
【学习笔记】线性基
2022-06-28 08:06:00 【仰望星空的蚂蚁】
感觉还是没太搞懂 qwq …
定义
设数集 T T T 的值域范围为 [ 1 , 2 n − 1 ] [1,2^n-1] [1,2n−1] 。
T T T 的线性基是 T T T 的一个 子集 A = { a 1 , a 2 , . . . , a n } A=\{a_1,a_2,...,a_n\} A={ a1,a2,...,an}
A A A 中所有元素互相 xor 所形成的异或集合,等价于原数集 T T T 的元素互相 xor 形成的异或集合。
可以理解为将原数集进行了压缩。
性质
- 线性基的异或集合中每一元素的异或方案 唯一
- 线性基二进制最高位互不相同
- 线性基中元素互相异或,异或集合不变。
- 线性基异或集合大小为 2 ∣ A ∣ 2^{|A|} 2∣A∣ ,每种元素出现次数恰为 2 n − ∣ A ∣ 2^{n-|A|} 2n−∣A∣ 。
插入
void ins(int x) {
for(int i=50;i>=0;i--) {
if(x>>i&1) {
if(a[i]) x^=a[i];
else {
a[i]=x;return;}
}
}
}
性质:对于 n n n 个数的集合,假设线性基为 S S S ,那么会生成 2 ∣ S ∣ 2^{|S|} 2∣S∣ 种 不同 的异或值 (一种异或值对应唯一的方式),一个值会出现 2 n − ∣ S ∣ 2^{n-|S|} 2n−∣S∣ 次。
重构
void rebuild() {
for(int i=50;i>=0;i--) {
for(int j=i-1;j>=0;j--) {
if(a[i]>>j&1) a[i]^=a[j];
}
}
for(int i=0;i<=50;i++) {
if(a[i]) p[cnt++]=a[i]
}
}
求第 K 小
根据性质 2 。
我们要将线性基改造成每一位相互独立。
所以查询的时候将 K K K 二进制拆分,对于 1 1 1 的位,就异或上对应的线性基。
最终得出的答案就是 K 小值。
void Kth(ll K) {
K--;
if(K>=(1<<cnt)) return -1;
ll res(0);
for(int i=0;i<cnt;i++) {
if(K>>i&1) res^=p[i];
}
return res;
}
求排名
不会。只能献上丑丑的代码。(应该有什么巧妙的方法吧 哈哈哈)
ll qry(int x) {
ll res(0),y(0);
for(int i=30;i>=0;i--) {
if(a[i]==0) {
if((y>>i&1)>(x>>i&1)) {
break;
}
}
else {
if(x>>i&1) {
res=(res+fpow(2,(i>0)?cnt[i-1]:0,10086))%10086;
}
if((x>>i&1)!=(y>>i&1)) {
y^=a[i];
}
}
}
if(y<x) res++;
return res;
}
边栏推荐
- Kubernetes理论基础
- HJ字符个数统计
- 2021 programming language ranking summary
- Study notes 22/1/11
- asp. Net datalist when there are multiple data displays
- B_QuRT_User_Guide(28)
- kubernetes集群命令行工具kubectl
- Do you know TCP protocol (2)?
- Ambari (V) ---ambari integrated Azkaban (valid for personal test)
- Rediscluster cluster mode capacity expansion node
猜你喜欢

MySQL two table connection principle (understand join buf)

Online WPS tool

Section 8: DMA of zynq

Eslint syntax monitoring off

Activity implicit jump

How to configure DDR3 of dm8148

sql主從複制搭建
![[JS] - [DFS, BFS application] - learning notes](/img/77/6f8d4ebe1d0b3ba036aea9358de793.png)
[JS] - [DFS, BFS application] - learning notes

Configuring MySQL multi instance master-slave synchronization for Linux

Redis one master multi slave cluster setup
随机推荐
SLAM中常用的雅克比矩阵J
B_QuRT_User_Guide(28)
Is it reliable to open an account by digging money? Is it safe?
【尚品汇】项目笔记
Buffer pool in MySQL
sql主从复制搭建
Airflow2 configuration windows azure SSO details based on oauth2 protocol
HJ质数因子
Upgrade HDP spark to spark 2.4.8 without upgrading ambari
nlp序列完全可以模拟人脑智能
Airflow2.1.1 ultra detailed installation document
十大券商注册开户靠谱吗?安全吗?
[JS] - [DFS, BFS application] - learning notes
Trigonometric transformation formula
挖财注册开户靠谱吗?安全吗?
Activity implicit jump
HJ delete the character with the least number of occurrences in the string
Redis cerebral fissure
Helloword routine for ROS
Configuring multiple instances of MySQL under Linux