LuoguU72177 火星人plus (逆康拓展开)
没开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 (逆康拓展开)的更多相关文章
- 康拓展开 & 逆康拓展开 知识总结(树状数组优化)
康拓展开 : 康拓展开,难道他是要飞翔吗?哈哈,当然不是了,康拓具体是哪位大叔,我也不清楚,重要的是 我们需要用到它后面的展开,提到展开,与数学相关的,肯定是一个式子或者一个数进行分解,即 展开. 到 ...
- hdoj-1027-Ignatius and the Princess II(逆康拓展开)
题目链接 /* Name: Copyright: Author: Date: 2018/5/2 11:07:16 Description:输出第m小的序列 */ #include <iostre ...
- 【康拓展开】及其在求全排列第k个数中的应用
题目:给出n个互不相同的字符, 并给定它们的相对大小顺序,这样n个字符的所有排列也会有一个顺序. 现在任给一个排列,求出在它后面的第i个排列.这是一个典型的康拓展开应用,首先我们先阐述一下什么是康拓展 ...
- ACM/ICPC 之 BFS(离线)+康拓展开(TSH OJ-玩具(Toy))
祝大家新年快乐,相信在新的一年里一定有我们自己的梦! 这是一个简化的魔板问题,只需输出步骤即可. 玩具(Toy) 描述 ZC神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...
- 九宫重拍(bfs + 康拓展开)
问题描述 如下面第一个图的九宫格中,放着 1~8 的数字卡片,还有一个格子空着.与空格子相邻的格子中的卡片可以移动到空格中.经过若干次移动,可以形成第二个图所示的局面. 我们把第一个图的局面记为:12 ...
- 【算法系列学习三】[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 反向bfs打表和康拓展开
[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 这是一道经典的八数码问题.首先,简单介绍一下八数码问题: 八数码问题也称为九宫问题.在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的 ...
- 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 ...
- ACM/ICPC 之 BFS(离线)+康拓展开 (HDU1430-魔板)
魔板问题,一道经典的康拓展开+BFS问题,为了实现方便,我用string类来表示字符串,此前很少用string类(因为不够高效,而且相对来说我对char数组的相关函数比较熟),所以在这里也发现了很多容 ...
- nyoj 139 我排第几个--康拓展开
我排第几个 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 现在有"abcdefghijkl”12个字符,将其所有的排列中按字典序排列,给出任意一种排列,说 ...
随机推荐
- 学习Linux须知1.0之Linux相关概念、工具(yum、vim)、防火墙等
温馨提示:重点掌握的前面都标注了 ☆ 一.Linux 是什么? Linux 是一个操作系统. 我们的 Linux 主要是系统调用和内核那两层. 当然直观地看,我们使用的操作系统还包含一些在其上运行的应 ...
- Sentinel与OpenFeign 服务熔断那些事
点赞再看,养成习惯,微信搜索[牧小农]关注我获取更多资讯,风里雨里,小农等你,很高兴能够成为你的朋友. 项目源码地址:公众号回复 sentinel,即可免费获取源码 在上一篇中,我们讲解了 Senti ...
- CentOS8安装mysql8.0具体步骤
操作系统:CentOS Linux release 8.0及以上 Mysql版本:Mysql 8.0.22 x86_64 (MySQL Community Server - GPL) Mysql8下载 ...
- C语言- 基础数据结构和算法 - 循环链表
听黑马程序员教程<基础数据结构和算法 (C版本)>,照着老师所讲抄的, 视频地址https://www.bilibili.com/video/BV1vE411f7Jh?p=1 喜欢的朋友可 ...
- 超级重磅!Apache Hudi多模索引对查询优化高达30倍
与许多其他事务数据系统一样,索引一直是 Apache Hudi 不可或缺的一部分,并且与普通表格式抽象不同. 在这篇博客中,我们讨论了我们如何重新构想索引并在 Apache Hudi 0.11.0 版 ...
- 15.LNMP架构的源码编译
LNMP架构的源码编译 目录 LNMP架构的源码编译 编译安装 Nginx 服务 1.关闭防火墙 2.安装相关依赖包 3.创建运行用户 4.解压软件包及配置编译安装 5.优化路径 6.将Nginx 加 ...
- SAP JSON 格式化及解析。
一.首选:/ui2/cl_json {'key':'value'} /ui2/cl_json=>deserialize( EXPORTING json = json CHANGING d ...
- RPA应用场景-营业收入核对
场景概述营业收入核对 所涉系统名称 SAP ,Excel,门店业务系统 人工操作(时间/次) 4 小时 所涉人工数量 6 操作频率每日 场景流程 1.每日13点起进入SAP查询前一日营业收入记账情况: ...
- rhel安装程序
Linux下软件分类 rpm软件包,包管理器 yum deb软件包,包管理器 apt 源代码软件包 一般为".tar.gz".&quo ...
- python常见的错误提示处理
python常见的错误有 NameError变量名错误 IndentationError代码缩进错误 AttributeError对象属性错误 TypeError类型错误 IOError输入输出错误 ...