题目



分析

考虑 \(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】计数题的更多相关文章

  1. JZOJ 【NOIP2017提高A组模拟9.14】捕老鼠

    JZOJ [NOIP2017提高A组模拟9.14]捕老鼠 题目 Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕 ...

  2. [JZOJ 100026] [NOIP2017提高A组模拟7.7] 图 解题报告 (倍增)

    题目链接: http://172.16.0.132/senior/#main/show/100026 题目: 有一个$n$个点$n$条边的有向图,每条边为$<i,f(i),w(i)>$,意 ...

  3. 【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 ...

  4. JZOJ 100029. 【NOIP2017提高A组模拟7.8】陪审团

    100029. [NOIP2017提高A组模拟7.8]陪审团 Time Limits: 1000 ms  Memory Limits: 131072 KB  Detailed Limits   Got ...

  5. JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线

    5328. [NOIP2017提高A组模拟8.22]世界线 (File IO): input:worldline.in output:worldline.out Time Limits: 1500 m ...

  6. JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器

    5329. [NOIP2017提高A组模拟8.22]时间机器 (File IO): input:machine.in output:machine.out Time Limits: 2000 ms M ...

  7. JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)

    5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...

  8. JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)

    5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...

  9. 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 ...

  10. 【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 ...

随机推荐

  1. 【实时数仓】Day06-数据可视化接口:接口介绍、Sugar大屏、成交金额、不同维度交易额(品牌、品类、商品spu)、分省的热力图 、新老顾客流量统计、字符云

    一.数据可视化接口介绍 1.设计思路 后把轻度聚合的结果保存到 ClickHouse 中后,提供即时的查询.统计.分析 展现形式:用于数据分析的BI工具[商业智能(Business Intellige ...

  2. Backbone 网络-ResNet v2 详解

    目录 目录 目录 前言 摘要 1.介绍 2.深度残差网络的分析 3.On the Importance of Identity Skip Connection 4.On the Usage of Ac ...

  3. HMS Core 6.8.0版本发布公告

    分析服务 ◆ 游戏行业新增"区服分析"埋点模板及分析报告,支持开发者分服务器查看用户付费.留存等指标,可进一步评估不同服务器的玩家质量: ◆ 新增营销活动报告,可查看广告任务带来的 ...

  4. http转成https工具类

    工具类代码如下: 点击查看代码 package com.astronaut.auction.modules.oss.utils; import org.apache.commons.collectio ...

  5. Python:界面开发,wx入门篇

    以下内容为本人的学习笔记,如需要转载,请声明原文链接微信公众号「englyf」https://mp.weixin.qq.com/s/3Yb_YAKiMte_f5HanetXiA 本文大概 3617 个 ...

  6. jmeter json提取器提取某个属性的所有值

    json 提取器各字段说明: Variable names:保存的变量名,后面使用${Variable names}引用 JSON Path  expressions:调试通过的json path表达 ...

  7. 使用IDEA创建一个maven的web项目并部署到tomcat上

    目录 1.创建一个maven项目 2.为项目添加配置文件 3.创建一些类和jsp页面 4.将项目部署到tomcat 1.创建一个maven项目 打开IDEA,File--New--Project 选择 ...

  8. Base58算法加密解密(Python实现)

    def b58encode(tmp:str) -> str: tmp = list(map(ord,tmp)) temp = tmp[0] base58 = "123456789ABC ...

  9. S2-008

    漏洞名称 S2-008(CVE-2012-0392) 远程代码执行漏洞 利用条件 Struts 2.0.0 - Struts 2.3.17 漏洞原理 S2-008 涉及多个漏洞,Cookie 拦截器错 ...

  10. Jasypt与Apollo一起使用造成Apollo热更新失效问题分析

    背景 近日业务同学反映在Apollo界面更改配置后, 服务中对应变量的值却没有改变 相关配置key定义如下: @ApolloJsonValue("${apollo.config.map:{} ...