当前位置:网站首页>【学习笔记】线性基
【学习笔记】线性基
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;
}
边栏推荐
- Doris学习笔记之介绍、编译安装与部署
- Helloword routine for ROS
- Prometheus deployment alarm docking QQ mailbox
- asp. Net datalist when there are multiple data displays
- How redis solves cache avalanche, breakdown and penetration problems
- Cloud native: cloud computing technology is upgraded again to open an era of comprehensive cloud development
- sql主从复制搭建
- Soft exam -- software designer -- afternoon question data flow diagram DFD
- asp. Net registration page
- 云原生:云计算技术再次升级 开启全面云开发时代
猜你喜欢

Section Xi. Axi of zynq_ Use of DMA

Airflow2.1.1 summary of the pits stepped on in actual combat!!

The solution of "user account control to continue, please enter administrator user name and password" appears in win10 Professional Edition

Online WPS tool

Configuring MySQL multi instance master-slave synchronization for Linux

A single node obtains the lock lock of the order number

Prometheus deployment alarm docking QQ mailbox

Disposition Flex

Introduction to Devops Basics

SLAM中常用的雅克比矩阵J
随机推荐
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
Section Xi. Axi of zynq_ Use of DMA
kubernetes集群命令行工具kubectl
Prometheus monitoring (I)
flex布局
2021 programming language ranking summary
ROS 笔记(08)— 服务数据的定义与使用
HJ成绩排序
Is it reliable for flush to register and open an account? Is it safe?
你了解TCP协议吗(二)?
抗洪救灾,共克时艰,城联优品捐赠10万元爱心物资驰援英德
Upgrade HDP spark to spark 2.4.8 without upgrading ambari
SOC timer and interrupt configuration
sql分析(查询截取分析做sql优化)
Redis cerebral fissure
SQL master-slave replication setup
Sentinel mechanism of redis cluster
Do you know TCP protocol (1)?
券商注册开户靠谱吗?安全吗?
Idea package together, using compact middle packages to solve &