BZOJ 3689: 异或之
2017-12-04 22:20
281 查看
这题还不错? 我好菜啊
po姐说的很清楚啊QAQ 直接去看就好了
代码打着打着就发现打得好短(躺
不过似乎不算很快 没怎么看黄学长那种做法(好像很快
po姐说的很清楚啊QAQ 直接去看就好了
代码打着打着就发现打得好短(躺
不过似乎不算很快 没怎么看黄学长那种做法(好像很快
#include<bits/stdc++.h> using namespace std; const int N=1e5+2,inf=(1ll<<31)-1; char O[1<<14],*S=O,*T=O; #define gc (S==T&&(T=(S=O)+fread(O,1,1<<14,stdin),S==T)?-1:*S++) inline int read(){ int x=0,f=1; char ch=gc; while(ch<'0' || ch>'9'){if(ch=='-')f=-1; if(ch<0)return 0; ch=gc;} while(ch>='0' && ch<='9'){x=(x<<1)+(x<<3)+ch-'0'; ch=gc;} return x*f; } int t[N*30][2],s[N*30],tot=0; int a ,p ,n,b[31]; void ins(int x){ int u=0; for(int i=30;~i;--i){ int y=(x&b[i])>0; if(!t[u][y])t[u][y]=++tot; u=t[u][y],++s[u]; } } int get(int x,int k){ if(k>n)return inf; int u=0,w=0; for(int i=30;~i;--i){ int y=(x&b[i])>0,o=s[ t[u][y] ]; if(o>=k) u=t[u][y]; else k-=o,u=t[u][y^1],w+=b[i]; } return w; } struct P{int u,x;}; bool operator <(const P &x,const P &y){ return x.u>y.u; } priority_queue<P>q; int main(){ n=read(); int m=read()<<1,i; b[0]=1; for(i=1;i<31;++i)b[i]=b[i-1]<<1; for(i=1;i<=n;++i) a[i]=read(),ins(a[i]),p[i]=2; for(i=1;i<=n;++i) q.push( (P){get(a[i],2),i} ); while(m--){ P o=q.top(); q.pop(); if(m&1)printf("%d ",o.u); o.u=get(a[o.x],++p[o.x]); q.push(o); } return 0; }
相关文章推荐
- BZOJ_3689_异或之_可持久化Trie+堆
- 【bzoj3689】【异或之】【trie树+堆】
- BZOJ 3689 异或之 Trie树+堆
- BZOJ[3689] 异或之 Trie树+堆
- BZOJ 3689 异或之
- bzoj 3689: 异或之 字典树+堆
- BZOJ 3689: 异或之
- BZOJ 3689 异或 Trie木+堆
- 【bzoj3689】异或之 可持久化Trie树+堆
- BZOJ3689 异或之
- 异或之(bzoj 3689)
- 【BZOJ3689】异或之 堆+可持久化Trie树
- [Trie树] BZOJ3689: 异或之
- bzoj 3689 异或之
- BZOJ3689 异或之
- BZOJ 3689: 异或之 字典树 优先队列
- [乱搞 || 可持久化字典树 堆] BZOJ3689 异或之
- 【bzoj3689】异或之 trie+堆
- [BZOJ 3689]异或之
- BZOJ3689: 异或之