没开long long见祖宗。。。

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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long //#define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin); #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; const int N = 100007;
#define int long long
int n; namespace BIT{
int t[N];
int tmp[N];
inline void Updata(int x, int w){
for(; x <= n; x += x&-x) t[x] += w;
}
inline int Query(int x){
int sum = 0;
for(; x; x -= x&-x) sum += t[x];
return sum;
}
inline void CreatContor(){
R(i,1,n){
int x;
io >> x;
Updata(x, 1);
tmp[i] = x - Query(x);
// D_e(tmp[i]);
}
}
} namespace SegTree{
int t[N << 2];
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
inline void Pushup(int rt){
t[rt] = t[rt << 1] + t[rt << 1 | 1];
}
inline void Build(int rt, int l, int r){
if(l == r){
t[rt] = 1;
return;
}
int mid = (l + r) >> 1;
Build(lson), Build(rson);
Pushup(rt);
}
inline void Updata(int rt, int l, int r, int x){
if(l == r){
t[rt] = 0;
return;
}
int mid = (l + r) >> 1;
if(mid >= x)
Updata(lson, x);
else
Updata(rson, x);
Pushup(rt);
}
inline int Query(int rt, int l, int r, int w){
if(l == r) return l;
int mid = (l + r) >> 1;
if(t[rt << 1] >= w)
return Query(lson, w);
else
return Query(rson, w - t[rt << 1]); }
}
#undef int
int main(){
#define int long long
FileOpen(); int m;
io >> n >> m; BIT::CreatContor(); //R(i,1,n) D_e(BIT::tmp[i]) ;
BIT::tmp[n] += m;
nR(i,n,1){
BIT::tmp[i - 1] += BIT::tmp[i] / (n - i + 1);
BIT::tmp[i] %= (n - i + 1);
// D_e(BIT::tmp[i]);
} SegTree::Build(1, 1, n); R(i,1,n-1){
//D_e(BIT::tmp[i]);
int x = SegTree::Query(1, 1, n, BIT::tmp[i] + 1);
printf("%d ", x);
SegTree::Updata(1, 1, n, x);
}
printf("%d", SegTree::Query(1, 1, n, BIT::tmp[n] + 1)); return 0;
}

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. Redis(1)- Redis数据库的安装和配置

    1.Redis安装 1.1.Linux环境安装Redis step-1:下载Redis 进入官网找到下载地址 https://redis.io/download wget https://github ...

  2. js算法-埃筛法

  3. 零成本搭建个人博客之图床和cdn加速

    本文属于零成本搭建个人博客指南系列 为什么要使用图床 博客文章中的图片资源文件一般采用本地相对/绝对路径引用,或者使用图床通过外链进行引用展示.本地引用的弊端我认为在于: 图片和博客放在同一个代码托管 ...

  4. Keil软件下用Jlink无法识别芯片

    Keil软件下用Jlink无法识别芯片 硬件:正点原子探索者 软件:keil J-Link固件版本:V9.40 J-Link V6.94b驱动:下载地址 跟着视频教程走,发现的第一个问题就是这个,记录 ...

  5. CentOS 8.0与CentOS7.0 防火墙端口设置

    一,开放端口号 firewall-cmd --zone=public --add-port=8080/tcp --permanent  #开启8080端口 firewall-cmd --zone=pu ...

  6. React项目配置npm run build命令分环境打包

    使用create-react-app脚手架创建的项目默认隐藏了webpack等配置文件信息,使用npm run eject命令暴露这些隐藏的配置文件信息 项目默认有两个环境:开发环境(npm star ...

  7. 开源流程引擎osworkflow、jbpm、activiti、flowable、camunda哪个好?

    市场上比较有名的开源流程引擎有osworkflow.jbpm.activiti.flowable.camunda.其中:Jbpm4.Activiti.Flowable.camunda四个框架同宗同源, ...

  8. 基于SqlSugar的开发框架循序渐进介绍(7)-- 在文件上传模块中采用选项模式【Options】处理常规上传和FTP文件上传

    在基于SqlSugar的开发框架的服务层中处理文件上传的时候,我们一般有两种处理方式,一种是常规的把文件存储在本地文件系统中,一种是通过FTP方式存储到指定的FTP服务器上.这种处理应该由程序进行配置 ...

  9. SmartIDE v0.1.19 - 码云(Gitee)最有价值开源项目奖项、工作区策略、类虚拟机镜像VMLC、Server安装手册

    SmartIDE v0.1.19 (CLI Build 3909, Server Build 3890) 已经发布,本次Sprint主要完成2个重要特性,工作区策略和类虚拟机容器(VM Like Co ...

  10. pytorch 中 repeat 和 expend 的功能和区别

    功能 均是用于扩展张量的维度 区别 tensor.expand(*sizes) 将张量中单维度(singleton dimensions,即张量在某个维度上为1的维度,exp(1,2,3),其中在第一 ...