当前位置:网站首页>[learning notes] linear basis
[learning notes] linear basis
2022-06-28 08:14:00 【Ants looking up at the stars】
I still don't feel that I understand qwq …
Definition
Set of assumptions T T T The range of values is [ 1 , 2 n − 1 ] [1,2^n-1] [1,2n−1] .
T T T The linear basis of is T T T One of the A subset of A = { a 1 , a 2 , . . . , a n } A=\{a_1,a_2,...,a_n\} A={ a1,a2,...,an}
A A A All elements in the are mutually xor The XOR set formed , Equivalent to the set of primitive numbers T T T The elements of each other xor An XOR set formed .
It can be understood as compressing the original number set .
nature
- The XOR scheme of each element in the XOR set of linear bases only
- The highest bit of linear basis binary is different from each other
- Elements in a linear basis are exclusive or to each other , The XOR set does not change .
- The linear base XOR set size is 2 ∣ A ∣ 2^{|A|} 2∣A∣ , The number of occurrences of each element is exactly 2 n − ∣ A ∣ 2^{n-|A|} 2n−∣A∣ .
Insert
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;}
}
}
}
nature : about n n n A collection of numbers , Suppose the linear basis is S S S , So it's going to generate 2 ∣ S ∣ 2^{|S|} 2∣S∣ Kind of Different Exclusive or values ( An exclusive or value corresponds to a unique way ), A value will appear 2 n − ∣ S ∣ 2^{n-|S|} 2n−∣S∣ Time .
restructure
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]
}
}
Please K Small
According to the nature 2 .
We need to transform the linear basis into each bit independent of each other .
So the query will K K K Binary split , about 1 1 1 Bit , On the corresponding linear basis on XOR .
The final answer is K Small value .
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;
}
Ranking
Can't . Only ugly code .( There should be some clever way Ha ha ha )
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;
}
边栏推荐
- Oracle view all tablespaces in the current library
- Today's notes 22/1/7
- Ambari (VIII) --- ambari integrated impala document (valid for personal test)
- Leetcode swing series
- Airflow2.1.1 summary of the pits stepped on in actual combat!!
- SQL analysis (query interception analysis for SQL optimization)
- Unity - use of API related to Pico development input system ---c
- redis02——一篇终结redis的五种数据类型操作命令(可学习、复习、面试、收藏备用)
- 22/02/15 study notes
- 你了解TCP协议吗(一)?
猜你喜欢
asp. Net upload image path and image name
B_ QuRT_ User_ Guide(27)
设置网页的标题部分的图标
Jacobian matrix J commonly used in slam
Idea package together, using compact middle packages to solve &
Eslint 语法监测关闭
Do you know TCP protocol (2)?
Three step problem of leetcode
The micro kernel zephyr is supported by many manufacturers!
MySQL two table connection principle (understand join buf)
随机推荐
Little artist huangxinyang was invited to participate in the Wuhan station of children's unit of Paris Fashion Week
How redis solves cache avalanche, breakdown and penetration problems
券商注册开户靠谱吗?安全吗?
【学习笔记】模拟
Dataset filling data, and the use of rows and columns
图像翻译/Transformer:ITTR: Unpaired Image-to-Image Translation with Transformers用Transfor进行非配对图像对图像的转换
Jenkins' common build trigger and hook services (V)
Do you know TCP protocol (2)?
B_ QuRT_ User_ Guide(27)
2022巴黎时装周儿童单元6.19武汉站圆满落幕
Jacobian matrix J commonly used in slam
App automated testing appium tutorial 2 - ADB command
redis02——一篇终结redis的五种数据类型操作命令(可学习、复习、面试、收藏备用)
SQL master-slave replication setup
PLSQL installation under Windows
十大券商注册开户靠谱吗?安全吗?
Airflow2.1.1 summary of the pits stepped on in actual combat!!
Devops foundation chapter Jenkins deployment (II)
解决npm ERR! Unexpected end of JSON input while parsing near问题
Reverse mapping of anonymous pages