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 ...
随机推荐
- eclipse 无法将节点解析到句柄
将 干掉即可
- SQL语句查询关键字前期数据准备
前期数据准备 create table emp( id int primary key auto_increment, name varchar(20) not null, gender enum(' ...
- html网页图片加载失败的友好处理方式
网络环境总是多样且复杂的,一张网页图片可能会因为网路状况差而加载失败或加载超长时间,也可能因为权限不足或者资源不存在而加载失败,这些都会导致用户体验变差,所以我们需要对图片加载失败时的情况进行一个弥补 ...
- Qt对象跨线程出现的问题记录,以及解决方案
Qt在跨线程开发的时候可能会出现不少问题,在这里记录一下 Qt目前用下来还是非常强大的,虽然只是用在桌面端程序开发上,但是其强大的桌面开发库真的挺好用的(Layout除外,你妈死了). Qt除了UI, ...
- 自定义RBAC(5)
您好,我是湘王,这是我的博客园,欢迎您来,欢迎您再来- 把实体类及Service类都准备好了之后,就可以开始继续写业务代码了.Spring Security的强大之一就在于它的拦截器.那么这里也可以参 ...
- 一文聊透Apache Hudi的索引设计与应用
Hudi索引在数据读和写的过程中都有应用.读的过程主要是查询引擎利用MetaDataTable使用索引进行Data Skipping以提高查找速度;写的过程主要应用在upsert写上,即利用索引查找该 ...
- python里面一些零碎知识点
1. Python中反斜杠可以用在一行结尾做续行符使用. 2. pytorch中,一般来说如果对tensor的一个函数后加上了下划线,则表明这是一个in-place类型.in-place类型是指,当在 ...
- 降本超30%,智聆口语通过 TKE 注册节点实现 IDC GPU 节点降本增效实践
背景介绍 腾讯云智聆口语评测(Smart Oral Evaluation,SOE)是腾讯云推出的中英文语音评测产品,支持从儿童到成人全年龄覆盖的语音评测,提供单词.句子.段落.自由说等多种评测模式,从 ...
- 如何用 Python 隐藏你的 API 密钥
你好,我是悦创. 博客首发:https://bornforthis.cn/posts/19.html 有时您需要在代码中存储敏感信息,例如密码或 API 密钥,而在 Python 中最简洁的方法是使用 ...
- 迁移学习(MixMatch)《MixMatch: A Holistic Approach to Semi-Supervised Learning》
论文信息 论文标题:MixMatch: A Holistic Approach to Semi-Supervised Learning论文作者:David Berthelot, Nicholas Ca ...