题目



分析

考虑 \(kruskal\) 的过程

我们选边从高位开始

当前位为 \(0\) 的放一边,为 \(1\) 的放另一边

将 \(0\) 的建一棵字典树, \(1\) 的匹配

因为是异或,那就走相同值的位,算能匹配到的最小值的个数

和与方案数都可以在这里计算

\(Code\)

  1. #include<cstdio>
  2. using namespace std;
  3. typedef long long LL;
  4. const LL P = 1e9 + 7;
  5. const int N = 100005;
  6. int n , cnt , su , a[N] , c[N] , d[N] , ts[N * 30] , t[N * 30][2];
  7. LL ans = 1;
  8. LL fpow(LL x , LL y)
  9. {
  10. LL res = 1;
  11. while (y)
  12. {
  13. if (y & 1) res = res * x % P;
  14. y >>= 1 , x = x * x % P;
  15. }
  16. return res;
  17. }
  18. void insert(int x)
  19. {
  20. int u = 0 , ch;
  21. for(register int i = 30; i >= 0; i--)
  22. {
  23. ch = (x >> i) & 1;
  24. if (!t[u][ch]) t[u][ch] = ++cnt;
  25. u = t[u][ch] , ts[u]++;
  26. }
  27. }
  28. int find(int x)
  29. {
  30. int u = 0 , ch , res = 0;
  31. for(register int i = 30; i >= 0; i--)
  32. {
  33. ch = (x >> i) & 1;
  34. if (t[u][ch]) u = t[u][ch];
  35. else u = t[u][ch ^ 1] , res = res + (1 << i);
  36. }
  37. su = ts[u];
  38. return res;
  39. }
  40. LL solve(int l , int r , int w)
  41. {
  42. if (l >= r) return 0;
  43. if (w == -1)
  44. {
  45. if (r - l - 1 > 0) ans = ans * fpow(r - l + 1 , r - l - 1) % P;
  46. return 0;
  47. }
  48. int tl = 0 , tr = 0;
  49. for(register int i = l; i <= r; i++)
  50. if (a[i] & (1 << w)) d[++tr] = a[i];
  51. else c[++tl] = a[i];
  52. for(register int i = 1; i <= tl; i++) a[l + i - 1] = c[i];
  53. for(register int i = 1; i <= tr; i++) a[l + tl - 1 + i] = d[i];
  54. int tmp;
  55. if (!tl || !tr) tmp = 0;
  56. else
  57. {
  58. int num = 0 , f; tmp = 2147483647 , cnt = 0;
  59. for(register int i = 1; i <= tl; i++) insert(c[i]);
  60. for(register int i = 1; i <= tr; i++)
  61. {
  62. su = 0 , f = find(d[i]);
  63. if (f < tmp) tmp = f , num = su;
  64. else if (tmp == f) num += su;
  65. }
  66. ans = ans * num % P;
  67. for(register int i = 0; i <= cnt; i++) ts[i] = t[i][0] = t[i][1] = 0;
  68. }
  69. return 1LL * tmp + solve(l , l + tl - 1 , w - 1) + solve(l + tl , r , w - 1);
  70. }
  71. int main()
  72. {
  73. freopen("jst.in" , "r" , stdin);
  74. freopen("jst.out" , "w" , stdout);
  75. scanf("%d" , &n);
  76. for(register int i = 1; i <= n; i++) scanf("%d" , &a[i]);
  77. printf("%lld\n" , solve(1 , n , 30));
  78. printf("%lld" , ans);
  79. }

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. ArcEngine 释放对象

    释放对象 例如IFeatureCursor,IFeatureClass等 ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(myFeatureCursor); ...

  2. 【每日一题】【字符串与数字互转】【去除空格】【大数处理】2021年12月12日-8. 字符串转换整数 (atoi)

    请你来实现一个 myAtoi(string s) 函数,使其能将字符串转换成一个 32 位有符号整数(类似 C/C++ 中的 atoi 函数). 函数 myAtoi(string s) 的算法如下: ...

  3. 基于EasyCode定制Mybatisplus全自动单表实现:新增/批量新增/修改/批量删除/分页查询/ID查询

    基于EasyCode定制Mybatisplus全自动单表实现CRUD接口 分页查询 ID查询 新增 批量新增 修改 批量删除 注意使用了MybatisPlus的自动填充功能,和insertBatchS ...

  4. websockets的原理

    一.应用场景 http 协议 客户端发起请求的时候才会返回内容,如果要处理类似于聊天室的应用,需要客户端不间断的发起请求(轮询),非常占用服务器的性能.所以websocket出现了. 二.ws(wss ...

  5. Law of Iterated Expectations & Covariance

    Law of Iterated Expectations \(E[Y] = E_X[E[Y |X]].\) The notation \(E_X[.]\) indicates the expectat ...

  6. 结合商业项目深入理解Go知识点

    这篇文章比较硬核,爆肝5千字,把之前整理的知识点都串起来了.建议先收藏,慢慢看. 前言 上一篇文章 #[Go WEB进阶实战]开源的电商前后台API系统 很受大家欢迎,有好多小伙伴私信我问题:&quo ...

  7. 巧用视觉障眼法,还原 3D 文字特效

    最近群里有这样一个有意思的问题,大家在讨论,使用 CSS 3D 能否实现如下所示的效果: 这里的核心难点在于,如何利用 CSS 实现一个立体的数字?CSS 能做到吗? 不是特别好实现,但是,如果仅仅只 ...

  8. [常用工具] mermaid学习笔记

    mermaid是一个基于Javascript的图表绘制工具,类似markdown用文本语法,用于描述文档图形(流程图. 时序图.甘特图),开发者可以通过一段mermaid文本来生成SVG或者PNG形式 ...

  9. 大数据 - ADS 数据可视化实现

    之前数据分层处理,最后把轻度聚合的结果保存到 ClickHouse 中,主要的目的就是提供即时的数据查询.统计.分析服务.这些统计服务一般会用两种形式展现,一种是为专业的数据分析人员的 BI 工具,一 ...

  10. 对于goland相对较新一些版本新建项目时没用go mod模式选项的坑

    前言 对于一些小白在网上看很早的一些go视频,使用goland2020.3.x版本或者其之前版本创建新项目,里面会有GO Modules(vgo)这个选项,也就是gomod模式创建新项目,然而对于现在 ...