没开long long见祖宗。。。

BIT先求逆序对来造表存展开关系,线段树维护01进制

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cmath>
  6. #define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
  7. #define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
  8. #define Max(a,b) ((a) > (b) ? (a) : (b))
  9. #define Min(a,b) ((a) < (b) ? (a) : (b))
  10. #define Fill(a,b) memset(a, b, sizeof(a))
  11. #define Abs(a) ((a) < 0 ? -(a) : (a))
  12. #define Swap(a,b) a^=b^=a^=b
  13. #define ll long long
  14. //#define ON_DEBUG
  15. #ifdef ON_DEBUG
  16. #define D_e_Line printf("\n\n----------\n\n")
  17. #define D_e(x) cout << #x << " = " << x << endl
  18. #define Pause() system("pause")
  19. #define FileOpen() freopen("in.txt","r",stdin);
  20. #else
  21. #define D_e_Line ;
  22. #define D_e(x) ;
  23. #define Pause() ;
  24. #define FileOpen() ;
  25. #endif
  26. struct ios{
  27. template<typename ATP>ios& operator >> (ATP &x){
  28. x = 0; int f = 1; char c;
  29. for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
  30. while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
  31. x*= f;
  32. return *this;
  33. }
  34. }io;
  35. using namespace std;
  36. const int N = 100007;
  37. #define int long long
  38. int n;
  39. namespace BIT{
  40. int t[N];
  41. int tmp[N];
  42. inline void Updata(int x, int w){
  43. for(; x <= n; x += x&-x) t[x] += w;
  44. }
  45. inline int Query(int x){
  46. int sum = 0;
  47. for(; x; x -= x&-x) sum += t[x];
  48. return sum;
  49. }
  50. inline void CreatContor(){
  51. R(i,1,n){
  52. int x;
  53. io >> x;
  54. Updata(x, 1);
  55. tmp[i] = x - Query(x);
  56. // D_e(tmp[i]);
  57. }
  58. }
  59. }
  60. namespace SegTree{
  61. int t[N << 2];
  62. #define lson rt << 1, l, mid
  63. #define rson rt << 1 | 1, mid + 1, r
  64. inline void Pushup(int rt){
  65. t[rt] = t[rt << 1] + t[rt << 1 | 1];
  66. }
  67. inline void Build(int rt, int l, int r){
  68. if(l == r){
  69. t[rt] = 1;
  70. return;
  71. }
  72. int mid = (l + r) >> 1;
  73. Build(lson), Build(rson);
  74. Pushup(rt);
  75. }
  76. inline void Updata(int rt, int l, int r, int x){
  77. if(l == r){
  78. t[rt] = 0;
  79. return;
  80. }
  81. int mid = (l + r) >> 1;
  82. if(mid >= x)
  83. Updata(lson, x);
  84. else
  85. Updata(rson, x);
  86. Pushup(rt);
  87. }
  88. inline int Query(int rt, int l, int r, int w){
  89. if(l == r) return l;
  90. int mid = (l + r) >> 1;
  91. if(t[rt << 1] >= w)
  92. return Query(lson, w);
  93. else
  94. return Query(rson, w - t[rt << 1]);
  95. }
  96. }
  97. #undef int
  98. int main(){
  99. #define int long long
  100. FileOpen();
  101. int m;
  102. io >> n >> m;
  103. BIT::CreatContor();
  104. //R(i,1,n) D_e(BIT::tmp[i]) ;
  105. BIT::tmp[n] += m;
  106. nR(i,n,1){
  107. BIT::tmp[i - 1] += BIT::tmp[i] / (n - i + 1);
  108. BIT::tmp[i] %= (n - i + 1);
  109. // D_e(BIT::tmp[i]);
  110. }
  111. SegTree::Build(1, 1, n);
  112. R(i,1,n-1){
  113. //D_e(BIT::tmp[i]);
  114. int x = SegTree::Query(1, 1, n, BIT::tmp[i] + 1);
  115. printf("%d ", x);
  116. SegTree::Updata(1, 1, n, x);
  117. }
  118. printf("%d", SegTree::Query(1, 1, n, BIT::tmp[n] + 1));
  119. return 0;
  120. }

LuoguU72177 火星人plus (逆康拓展开)的更多相关文章

  1. 康拓展开 & 逆康拓展开 知识总结(树状数组优化)

    康拓展开 : 康拓展开,难道他是要飞翔吗?哈哈,当然不是了,康拓具体是哪位大叔,我也不清楚,重要的是 我们需要用到它后面的展开,提到展开,与数学相关的,肯定是一个式子或者一个数进行分解,即 展开. 到 ...

  2. hdoj-1027-Ignatius and the Princess II(逆康拓展开)

    题目链接 /* Name: Copyright: Author: Date: 2018/5/2 11:07:16 Description:输出第m小的序列 */ #include <iostre ...

  3. 【康拓展开】及其在求全排列第k个数中的应用

    题目:给出n个互不相同的字符, 并给定它们的相对大小顺序,这样n个字符的所有排列也会有一个顺序. 现在任给一个排列,求出在它后面的第i个排列.这是一个典型的康拓展开应用,首先我们先阐述一下什么是康拓展 ...

  4. ACM/ICPC 之 BFS(离线)+康拓展开(TSH OJ-玩具(Toy))

    祝大家新年快乐,相信在新的一年里一定有我们自己的梦! 这是一个简化的魔板问题,只需输出步骤即可. 玩具(Toy) 描述 ZC神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...

  5. 九宫重拍(bfs + 康拓展开)

    问题描述 如下面第一个图的九宫格中,放着 1~8 的数字卡片,还有一个格子空着.与空格子相邻的格子中的卡片可以移动到空格中.经过若干次移动,可以形成第二个图所示的局面. 我们把第一个图的局面记为:12 ...

  6. 【算法系列学习三】[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 反向bfs打表和康拓展开

    [kuangbin带你飞]专题二 搜索进阶 之 A-Eight 这是一道经典的八数码问题.首先,简单介绍一下八数码问题: 八数码问题也称为九宫问题.在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的 ...

  7. Eight (HDU - 1043|POJ - 1077)(A* | 双向bfs+康拓展开)

    The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've see ...

  8. ACM/ICPC 之 BFS(离线)+康拓展开 (HDU1430-魔板)

    魔板问题,一道经典的康拓展开+BFS问题,为了实现方便,我用string类来表示字符串,此前很少用string类(因为不够高效,而且相对来说我对char数组的相关函数比较熟),所以在这里也发现了很多容 ...

  9. nyoj 139 我排第几个--康拓展开

    我排第几个 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 现在有"abcdefghijkl”12个字符,将其所有的排列中按字典序排列,给出任意一种排列,说 ...

随机推荐

  1. 学习Linux须知1.0之Linux相关概念、工具(yum、vim)、防火墙等

    温馨提示:重点掌握的前面都标注了 ☆ 一.Linux 是什么? Linux 是一个操作系统. 我们的 Linux 主要是系统调用和内核那两层. 当然直观地看,我们使用的操作系统还包含一些在其上运行的应 ...

  2. Sentinel与OpenFeign 服务熔断那些事

    点赞再看,养成习惯,微信搜索[牧小农]关注我获取更多资讯,风里雨里,小农等你,很高兴能够成为你的朋友. 项目源码地址:公众号回复 sentinel,即可免费获取源码 在上一篇中,我们讲解了 Senti ...

  3. CentOS8安装mysql8.0具体步骤

    操作系统:CentOS Linux release 8.0及以上 Mysql版本:Mysql 8.0.22 x86_64 (MySQL Community Server - GPL) Mysql8下载 ...

  4. C语言- 基础数据结构和算法 - 循环链表

    听黑马程序员教程<基础数据结构和算法 (C版本)>,照着老师所讲抄的, 视频地址https://www.bilibili.com/video/BV1vE411f7Jh?p=1 喜欢的朋友可 ...

  5. 超级重磅!Apache Hudi多模索引对查询优化高达30倍

    与许多其他事务数据系统一样,索引一直是 Apache Hudi 不可或缺的一部分,并且与普通表格式抽象不同. 在这篇博客中,我们讨论了我们如何重新构想索引并在 Apache Hudi 0.11.0 版 ...

  6. 15.LNMP架构的源码编译

    LNMP架构的源码编译 目录 LNMP架构的源码编译 编译安装 Nginx 服务 1.关闭防火墙 2.安装相关依赖包 3.创建运行用户 4.解压软件包及配置编译安装 5.优化路径 6.将Nginx 加 ...

  7. SAP JSON 格式化及解析。

    一.首选:/ui2/cl_json     {'key':'value'} /ui2/cl_json=>deserialize( EXPORTING json = json CHANGING d ...

  8. RPA应用场景-营业收入核对

    场景概述营业收入核对 所涉系统名称 SAP ,Excel,门店业务系统 人工操作(时间/次) 4 小时 所涉人工数量 6 操作频率每日 场景流程 1.每日13点起进入SAP查询前一日营业收入记账情况: ...

  9. rhel安装程序

    Linux下软件分类     rpm软件包,包管理器 yum     deb软件包,包管理器 apt     源代码软件包            一般为".tar.gz".&quo ...

  10. python常见的错误提示处理

    python常见的错误有 NameError变量名错误 IndentationError代码缩进错误 AttributeError对象属性错误 TypeError类型错误 IOError输入输出错误 ...