只 AC #11,其余都 WA 求调

P5283 [十二省联考 2019] 异或粽子

记得关注 ```cpp #include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; const int N=20000000+10; struct Node{int id,rk;long long w;bool operator <(const Node &a)const{return w<a.w;}}; priority_queue<Node>q; long long ans=1,x,s[N]; int a[N][2],size[N],n,m,tot; void ins(long long x) { int u=0; for(int i=31;i>=0;i--) { int ch=(x>>i)&1;size[u]++; if(!a[u][ch])a[u][ch]=++tot; u=a[u][ch]; } size[u]++; } long long query(long long x,int rk) { int u=0;long long ans=0; for(int i=31;i>=0;i--) { int ch=(x>>i)&1;//cout<<u<<" "<<ch<<" "<<size[a[u][1]]<<" "; if(!a[u][ch^1])u=a[u][ch]; else if(rk<=size[a[u][ch^1]])u=a[u][ch^1],ans|=1LL<<i; else rk-=size[a[u][ch^1]],u=a[u][ch]; } return ans; } long long getin() { long long x=0;char ch=getchar(); while(ch<'0'||ch>'9')ch=getchar(); while(ch>='0'&&ch<='9')x=x*10+ch-48,ch=getchar(); return x; } int main() { n=getin(),m=getin();m<<=1; for(int i=1;i<=n;i++)x=getin(),s[i]=s[i-1]^x; for(int i=0;i<=n;i++)ins(s[i]); for(int i=0;i<=n;i++)q.push((Node){i,1,query(s[i],1)}); for(int i=1;i<=m;i++) { Node t=q.top();ans+=t.w;q.pop();//cout<<t.id<<" "<<t.rk<<" "<<t.w<<endl; if(t.rk<n)q.push((Node){t.id,t.rk+1,query(s[t.id],t.rk+1)}); } cout<<(ans>>1)<<endl; }
by AlexSong @ 2024-01-29 11:46:17


@[AlexSong](/user/1004299) 这不就第一篇题解吗。。。不想好好调可以不调。。。
by Eirin_Yagokoro @ 2024-01-29 11:47:15


哦哦哦又在卷
by Wf_yjqd @ 2024-01-29 11:58:15


AC 了,trie 里有两步操作反了。 此帖结。
by Eirin_Yagokoro @ 2024-01-29 12:23:46


|