JZOJ 5352. 【NOIP2017提高A组模拟9.7】计数题
题目


分析
考虑 \(kruskal\) 的过程
我们选边从高位开始
当前位为 \(0\) 的放一边,为 \(1\) 的放另一边
将 \(0\) 的建一棵字典树, \(1\) 的匹配
因为是异或,那就走相同值的位,算能匹配到的最小值的个数
和与方案数都可以在这里计算
\(Code\)
#include<cstdio>
using namespace std;
typedef long long LL;
const LL P = 1e9 + 7;
const int N = 100005;
int n , cnt , su , a[N] , c[N] , d[N] , ts[N * 30] , t[N * 30][2];
LL ans = 1;
LL fpow(LL x , LL y)
{
	LL res = 1;
	while (y)
	{
		if (y & 1) res = res * x % P;
		y >>= 1 , x = x * x % P;
	}
	return res;
}
void insert(int x)
{
	int u = 0 , ch;
	for(register int i = 30; i >= 0; i--)
	{
		ch = (x >> i) & 1;
		if (!t[u][ch]) t[u][ch] = ++cnt;
		u = t[u][ch] , ts[u]++;
	}
}
int find(int x)
{
	int u = 0 , ch , res = 0;
	for(register int i = 30; i >= 0; i--)
	{
		ch = (x >> i) & 1;
		if (t[u][ch]) u = t[u][ch];
		else u = t[u][ch ^ 1] , res = res + (1 << i);
	}
	su = ts[u];
	return res;
}
LL solve(int l , int r , int w)
{
	if (l >= r) return 0;
	if (w == -1)
	{
		if (r - l - 1 > 0) ans = ans * fpow(r - l + 1 , r - l - 1) % P;
		return 0;
	}
	int tl = 0 , tr = 0;
	for(register int i = l; i <= r; i++)
	if (a[i] & (1 << w)) d[++tr] = a[i];
	else c[++tl] = a[i];
	for(register int i = 1; i <= tl; i++) a[l + i - 1] = c[i];
	for(register int i = 1; i <= tr; i++) a[l + tl - 1 + i] = d[i];
	int tmp;
	if (!tl || !tr) tmp = 0;
	else
	{
		int num = 0 , f; tmp = 2147483647 , cnt = 0;
		for(register int i = 1; i <= tl; i++) insert(c[i]);
		for(register int i = 1; i <= tr; i++)
		{
			su = 0 , f = find(d[i]);
			if (f < tmp) tmp = f , num = su;
			else if (tmp == f) num += su;
		}
		ans = ans * num % P;
		for(register int i = 0; i <= cnt; i++) ts[i] = t[i][0] = t[i][1] = 0;
	}
	return 1LL * tmp + solve(l , l + tl - 1 , w - 1) + solve(l + tl , r , w - 1);
} 
int main()
{
	freopen("jst.in" , "r" , stdin);
	freopen("jst.out" , "w" , stdout);
	scanf("%d" , &n);
	for(register int i = 1; i <= n; i++) scanf("%d" , &a[i]);
	printf("%lld\n" , solve(1 , n , 30));
	printf("%lld" , ans);
}
JZOJ 5352. 【NOIP2017提高A组模拟9.7】计数题的更多相关文章
- JZOJ 【NOIP2017提高A组模拟9.14】捕老鼠
		JZOJ [NOIP2017提高A组模拟9.14]捕老鼠 题目 Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕 ... 
- [JZOJ 100026] [NOIP2017提高A组模拟7.7] 图 解题报告 (倍增)
		题目链接: http://172.16.0.132/senior/#main/show/100026 题目: 有一个$n$个点$n$条边的有向图,每条边为$<i,f(i),w(i)>$,意 ... 
- 【NOIP2017提高A组模拟9.7】JZOJ 计数题
		[NOIP2017提高A组模拟9.7]JZOJ 计数题 题目 Description Input Output Sample Input 5 2 2 3 4 5 Sample Output 8 6 D ... 
- JZOJ 100029. 【NOIP2017提高A组模拟7.8】陪审团
		100029. [NOIP2017提高A组模拟7.8]陪审团 Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limits Got ... 
- JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线
		5328. [NOIP2017提高A组模拟8.22]世界线 (File IO): input:worldline.in output:worldline.out Time Limits: 1500 m ... 
- JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器
		5329. [NOIP2017提高A组模拟8.22]时间机器 (File IO): input:machine.in output:machine.out Time Limits: 2000 ms M ... 
- JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)
		5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ... 
- JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林  (Standard IO)
		5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ... 
- JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)
		5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ... 
- 【NOIP2017提高A组模拟9.17】信仰是为了虚无之人
		[NOIP2017提高A组模拟9.17]信仰是为了虚无之人 Description Input Output Sample Input 3 3 0 1 1 7 1 1 6 1 3 2 Sample O ... 
随机推荐
- 关于最新版本listen1 (2.1.6)的修改心得(添加下载功能)
			注:本文只作为技术交流 前言 再次感谢 listen1 的作者开发出如此强大的音乐播放器 项目地址 上一篇的文章没有解决跨域问题(命名不能正确命名), 上一篇文章 地址 这次解决了,并简单的美化了下载 ... 
- form表单里的button 等元素不能使用margin: 0 auto;
			记得把form和button都设为display:block; 就能用margin: 0 auto;水平居中了 
- python语法之注释
			引言 注释的最大作用是提高程序的可读性,在开发过程中非常有必要加上注释.Python 支持两种类型的注释,分别是单行注释和多行注释. 1 单行注释 Python 使用井号#作为单行注释的符号,语法格式 ... 
- Codeforces Round #838 (Div. 2) D. GCD Queries
			题意 有个长度为n的排列p,[0,1,2,...n-1],你可以进行至多2*n次询问,每次询问两个i,j,返回gcd(pi,pj),让你在规定时间内猜出0在哪两个位置之一 思路 这是一道交互题,询问的 ... 
- [机器学习] Yellowbrick使用笔记2-模型选择
			在本教程中,我们将查看各种Scikit Learn模型的分数,并使用Yellowbrick的可视化诊断工具对它们进行比较,以便为我们的数据选择最佳的模型. 代码下载 文章目录 1 使用说明 1.1 模 ... 
- K8s 为什么会抛弃 docker
			为什么 K8s 会抛弃 docker 前言 CRI containerd 参考 为什么 K8s 会抛弃 docker 前言 在这之前先来了解下,k8s 是如何和 docker 进行交互的. CRI k ... 
- 《STL源码剖析》traits技法分析
			在完成一个迭代器的时候,我们可能会暴露太多的细节在外面,为了将这些细节给隐藏,我们需要封装,这也是为什么每一种STL容器都提供了一种专属的迭代器. 为了解决以"迭代器所指对象的型别" ... 
- BC3-牛牛学说话之-整数
			题目描述 牛牛刚刚出生,嗷嗷待哺,一开始他只能学说简单的数字,你跟他说一个整数,他立刻就能学会.输入一个整数,输出这个整数. 输入描述 输入一个整数,范围在32位有符号整数范围内 输出描述 输出这个整 ... 
- Ubuntu desktop 文件的书写格式
			首先切换到存放 desktop 文件的目录下,编辑好就可以保存了 cd /usr/share/applications/ vim name.desktop [Desktop Entry] Name=显 ... 
- JS按空格和换行或者其他字符进行切割形成数组
			据我所测试,目前最好用的代码是: 方案一 let arr = value.split(/[,,\s\n]/).filter(_ => _) 方案二 let arr = value.replace ... 
