当前位置:网站首页>Linear basis count (k large XOR sum)
Linear basis count (k large XOR sum)
2022-06-26 13:58:00 【__ LazyCat__】
Linear basis counting (k Great difference or and )
link :#114. k Great difference or and - subject - LibreOJ (loj.ac)
The question : Given a reproducible set S, Ask many times for the first k Small true subsets XOR and .
Answer key : Reconstruct the linear basis , send p [ i ] p[i] p[i] Of the j Bit in p [ j ] p[j] p[j] In case of existence, it is not 1, So XOR p [ j ] p[j] p[j] It must make the value larger , Abstracting into binary is to take p [ j ] p[j] p[j] amount to j Position fetching 1, Then you can put k Check the XOR result by bit .
tips: When the number of linear bases c n t cnt cnt Less than n when , Explain the non full rank , All results can be XOR 0, So it seems that the 1 As small as 0 Instead of p [ 0 ] p[0] p[0], So for k Minus one . The total XOR result is no more than 2 c n t − 1 2^{cnt}-1 2cnt−1 Of .
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=55;
ll p[maxn],f[maxn],cnt,n,m,ans,u,v,w;
inline void insert(ll x)
{
for(int i=50;i>=0;i--)
{
if(x>>i&1)
{
if(!p[i]){
p[i]=x; break;}
x^=p[i];
}
}
return;
}
inline void rebuild()
{
for(int i=0;i<=50;i++)
{
for(int j=i-1;j>=0;j--)
{
if(p[i]>>j&1)p[i]^=p[j];
}
if(p[i])f[cnt++]=p[i];
}
return;
}
inline ll query(ll k)
{
if(cnt!=n)k--;
if(k>=(1ll<<cnt))return -1;
ll ans=0;
for(int i=0;i<cnt;i++)ans^=f[i]*(k>>i&1);
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>u,insert(u);
}
rebuild(),cin>>m;
for(int i=1;i<=m;i++)
{
ll k; cin>>k,cout<<query(k)<<"\n";
}
return 0;
}
边栏推荐
- Here document interaction free and expect automatic interaction
- 8.Ribbon负载均衡服务调用
- [hcsd application development training camp] one line of code second cloud evaluation article - experience from the experiment process
- 7-16 monetary system I
- C language ---getchar() and putchar()
- 虫子 内存管理 下 内存注意点
- 虫子 内存管理 上
- 证券开户安全吗,有没有什么危险啊
- KITTI Tracking dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
- Awk tools
猜你喜欢

ES基於Snapshot(快照)的數據備份和還原

Cloudcompare - Poisson reconstruction

Range of types

使用 Performance 看看浏览器在做什么

ICML 2022 | LIMO: 一种快速生成靶向分子的新方法

Included angle of 3D vector

微信小程序注册指引

Zero basics of C language lesson 8: Functions

AGCO AI frontier promotion (6.26)

Here document interaction free and expect automatic interaction
随机推荐
2021-10-09
古瑞瓦特冲刺港交所上市:创下“多个第一”,获IDG资本9亿元投资
MySQL configuration improves data insertion efficiency
CF676C Vasya and String
使用 Performance 看看浏览器在做什么
证券开户安全吗,有没有什么危险啊
KITTI Detection dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
Luogu p3426 [poi2005]sza-template solution
D中不用GC
三维向量的夹角
GEE——全球人类居住区网格数据 1975-1990-2000-2014
Mongodb series window environment deployment configuration
嵌入式virlog代码运行流程
虫子 类和对象 中
Reprint - easy to use wechat applet UI component library
Exercises under insect STL string
免费的机器学习数据集网站(6300+数据集)
网络远程访问的方式使用树莓派
程序员必备,一款让你提高工作效率N倍的神器uTools
虫子 STL string 下 练习题