hdu 5269 ZYB loves Xor I

今晚best code第二题
好好学了下字典树,确实自己会的东西实在太少了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<list>
#include<vector>
#include<cstring>
#define inf 1<<30
#define Inf -1<<30
#define maxn 50000+5
#define ll long long
#define mod 998244353
#define uli unsigned long int
#define f_(i,x,n) for(int i=x;i<=n;i++)
#define F_(i,x,n) for(int i=x;i>=n;i--)
using namespace std;
int n;
struct stu
{
	int sum;
	stu *next[2];
	stu()
	{
		sum=0;
		next[0]=next[1]=NULL;
	}
};
void add(stu*root,int x)
{
	f_(i,0,30)
	{
		int m=x%2;
		x/=2;
		if(root->next[m]==NULL)
		{
			root->next[m]=new stu(); 
		}
		root=root->next[m];
		root->sum++;
	}
}
ll solve(stu*root,int cnt)
{
	ll re=0,l,r;
	if(root->next[0]==NULL) l=0;
	else 
	{
		l=root->next[0]->sum;
		re=(re+solve(root->next[0],cnt+1))%mod;
	}
	if(root->next[1]==NULL) r=0;
	else 
	{
		r=root->next[1]->sum;
		re=(re+solve(root->next[1],cnt+1))%mod;
	}
	re+=l*r*(1<<cnt)%mod;
	return re;
}
int main()
{
	int casee=1;
	cin.sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n;
		stu *root=new stu();
		f_(i,0,n-1)
		{
			int x;
			cin>>x;
			add(root,x);
		}
		cout<<"Case #"<<casee++<<": ";
		cout<<solve(root,0)*2%mod<<endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值