当前位置:网站首页>【学习笔记】线性基
【学习笔记】线性基
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;
}
边栏推荐
- Introduction to kubernetes (I)
- Install haproxy
- Idea package together, using compact middle packages to solve &
- asp. Net registration page
- SQL analysis (query interception analysis for SQL optimization)
- Section VI UART of zynq
- flex布局
- sql分析(查询截取分析做sql优化)
- A single node obtains the lock lock of the order number
- Airflow2.1.1 summary of the pits stepped on in actual combat!!
猜你喜欢
MySQL implements transaction persistence using redo logs
Prometheus monitoring (I)
Devops foundation chapter Jenkins deployment (II)
SOC clock configuration
Kubernetes cluster command line tool kubectl
asp. Net upload image path and image name
ROS notes (08) - definition and use of service data
LeetCode之三步问题
MySQL row format parsing
asp. Net registration page
随机推荐
[JS] - [throttling and anti shake function]
Study notes 22/1/17
Prometheus + grafana + MySQL master-slave replication + host monitoring
MySQL row format parsing
2021 programming language ranking summary
Localization SoC development plan
Is it reliable for the top ten securities companies to register and open accounts? Is it safe?
asp. Net upload image path and image name
Leetcode摆动序列系列
Kubernetes theoretical basis
Leetcode learning records
ROS notes (08) - definition and use of service data
你了解TCP协议吗(一)?
B_QuRT_User_Guide(29)
Jenkins' common build trigger and hook services (V)
Airflow2.x distributed deployment DAG execution failure log cannot be obtained normally
小艺人黄鑫洋受邀参加巴黎时装周儿童单元武汉站
2022巴黎时装周儿童单元6.19武汉站圆满落幕
HJ base conversion
HJ字符串排序