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 ...
随机推荐
- ArcEngine 释放对象
释放对象 例如IFeatureCursor,IFeatureClass等 ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(myFeatureCursor); ...
- 【每日一题】【字符串与数字互转】【去除空格】【大数处理】2021年12月12日-8. 字符串转换整数 (atoi)
请你来实现一个 myAtoi(string s) 函数,使其能将字符串转换成一个 32 位有符号整数(类似 C/C++ 中的 atoi 函数). 函数 myAtoi(string s) 的算法如下: ...
- 基于EasyCode定制Mybatisplus全自动单表实现:新增/批量新增/修改/批量删除/分页查询/ID查询
基于EasyCode定制Mybatisplus全自动单表实现CRUD接口 分页查询 ID查询 新增 批量新增 修改 批量删除 注意使用了MybatisPlus的自动填充功能,和insertBatchS ...
- websockets的原理
一.应用场景 http 协议 客户端发起请求的时候才会返回内容,如果要处理类似于聊天室的应用,需要客户端不间断的发起请求(轮询),非常占用服务器的性能.所以websocket出现了. 二.ws(wss ...
- Law of Iterated Expectations & Covariance
Law of Iterated Expectations \(E[Y] = E_X[E[Y |X]].\) The notation \(E_X[.]\) indicates the expectat ...
- 结合商业项目深入理解Go知识点
这篇文章比较硬核,爆肝5千字,把之前整理的知识点都串起来了.建议先收藏,慢慢看. 前言 上一篇文章 #[Go WEB进阶实战]开源的电商前后台API系统 很受大家欢迎,有好多小伙伴私信我问题:&quo ...
- 巧用视觉障眼法,还原 3D 文字特效
最近群里有这样一个有意思的问题,大家在讨论,使用 CSS 3D 能否实现如下所示的效果: 这里的核心难点在于,如何利用 CSS 实现一个立体的数字?CSS 能做到吗? 不是特别好实现,但是,如果仅仅只 ...
- [常用工具] mermaid学习笔记
mermaid是一个基于Javascript的图表绘制工具,类似markdown用文本语法,用于描述文档图形(流程图. 时序图.甘特图),开发者可以通过一段mermaid文本来生成SVG或者PNG形式 ...
- 大数据 - ADS 数据可视化实现
之前数据分层处理,最后把轻度聚合的结果保存到 ClickHouse 中,主要的目的就是提供即时的数据查询.统计.分析服务.这些统计服务一般会用两种形式展现,一种是为专业的数据分析人员的 BI 工具,一 ...
- 对于goland相对较新一些版本新建项目时没用go mod模式选项的坑
前言 对于一些小白在网上看很早的一些go视频,使用goland2020.3.x版本或者其之前版本创建新项目,里面会有GO Modules(vgo)这个选项,也就是gomod模式创建新项目,然而对于现在 ...