loj2472 「九省联考 2018」IIIDX
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
int n, a[500005], fa[500005], siz[500005], cnt[500005], ans[500005];
int hmn[500005];
double k;
bool vis[500005];
struct SGT{
int val[2000005], tag[2000005];
void build(int o, int l, int r){
if(l==r) val[o] = l;
else{
int mid=(l+r)>>1;
int lson=o<<1;
int rson=lson|1;
if(l<=mid) build(lson, l, mid);
if(mid<r) build(rson, mid+1, r);
val[o] = min(val[lson], val[rson]);
}
}
void pushDown(int o, int lson, int rson){
tag[lson] += tag[o];
tag[rson] += tag[o];
val[lson] += tag[o];
val[rson] += tag[o];
tag[o] = 0;
}
void update(int o, int l, int r, int x, int y, int k){
if(l>=x && r<=y){
val[o] += k;
tag[o] += k;
}
else{
int mid=(l+r)>>1;
int lson=o<<1;
int rson=lson|1;
if(tag[o]) pushDown(o, lson, rson);
if(x<=mid) update(lson, l, mid, x, y, k);
if(mid<y) update(rson, mid+1, r, x, y, k);
val[o] = min(val[lson], val[rson]);
}
}
int query(int o, int l, int r, int x){
if(l==r) return val[o]>=x?l:l+1;
else{
int mid=(l+r)>>1;
int lson=o<<1;
int rson=lson|1;
if(tag[o]) pushDown(o, lson, rson);
if(val[rson]>=x) return query(lson, l, mid, x);
else return query(rson, mid+1, r, x);
}
}
}sgt;
bool cmp(int a, int b){
return a>b;
}
int main(){
cin>>n>>k;
for(int i=1; i<=n; i++){
siz[i] = 1;
fa[i] = i / k;
scanf("%d", &a[i]);
}
sort(a+1, a+1+n, cmp);
for(int i=n; i; i--){
siz[fa[i]] += siz[i];
if(a[i]!=a[i+1]) cnt[i] = 0;
else cnt[i] = cnt[i+1] + 1;
}
sgt.build(1, 1, n);
for(int i=1; i<=n; i++){
if(fa[i] && !vis[fa[i]]){
sgt.update(1, 1, n, ans[fa[i]], n, siz[fa[i]]-1);
vis[fa[i]] = true;
}
int x=sgt.query(1, 1, n, siz[i]);
x += cnt[x]; hmn[x]++; x -= hmn[x] - 1;
ans[i] = x;
sgt.update(1, 1, n, x, n, -siz[i]);
}
for(int i=1; i<=n; i++)
printf("%d ", a[ans[i]]);
printf("\n");
return 0;
}
loj2472 「九省联考 2018」IIIDX的更多相关文章
- 「九省联考 2018」IIIDX 解题报告
「九省联考 2018」IIIDX 这什么鬼题,送的55分要拿稳,实测有60? 考虑把数值从大到小摆好,每个位置\(i\)维护一个\(f_i\),表示\(i\)左边比它大的(包括自己)还有几个数可以选 ...
- LOJ #2473. 「九省联考 2018」秘密袭击
#2473. 「九省联考 2018」秘密袭击 链接 分析: 首先枚举一个权值W,计算这个多少个连通块中,第k大的数是这个权值. $f[i][j]$表示到第i个节点,有j个大于W数的连通块的个数.然后背 ...
- Loj #2479. 「九省联考 2018」制胡窜
Loj #2479. 「九省联考 2018」制胡窜 题目描述 对于一个字符串 \(S\),我们定义 \(|S|\) 表示 \(S\) 的长度. 接着,我们定义 \(S_i\) 表示 \(S\) 中第 ...
- LOJ 2743(洛谷 4365) 「九省联考 2018」秘密袭击——整体DP+插值思想
题目:https://loj.ac/problem/2473 https://www.luogu.org/problemnew/show/P4365 参考:https://blog.csdn.net/ ...
- 【LOJ】#2479. 「九省联考 2018」制胡窜
题解 老了,国赛之前敲一个后缀树上LCT和线段树都休闲的很 现在后缀树上线段树合并差点把我写死 主要思路就是后缀树+线段树合并+容斥,我相信熟练的OIer看到这已经会了 但就是不想写 但是由于我过于老 ...
- LOJ#2471「九省联考 2018」一双木棋 MinMax博弈+记搜
题面 戳这里 题解 因为每行取的数的个数是单调不增的,感觉状态数不会很多? 怒而记搜,结果过了... #include<bits/stdc++.h> #define For(i,x,y) ...
- [loj 2478][luogu P4843]「九省联考 2018」林克卡特树
传送门 Description 小L 最近沉迷于塞尔达传说:荒野之息(The Legend of Zelda: Breath of The Wild)无法自拔,他尤其喜欢游戏中的迷你挑战. 游戏中有一 ...
- @loj - 2478@「九省联考 2018」林克卡特树
目录 @description@ @solution@ @part - 1@ @part - 2@ @accepted code@ @details@ @description@ 小 L 最近沉迷于塞 ...
- [九省联考2018]秘密袭击coat
[九省联考2018]秘密袭击coat 研究半天题解啊... 全网几乎唯一的官方做法的题解:链接 别的都是暴力.... 要是n=3333暴力就完了. 一.问题转化 每个联通块第k大的数,直观统计的话,会 ...
随机推荐
- 监控系统-mod-gearman
doc http://labs.consol.de/nagios/mod-gearman/ 安装 yum -y install gearmand-server-0.33-2.rhel6.x86_64. ...
- COGS 2075. [ZLXOI2015][异次元圣战III]ZLX的陨落
★★☆ 输入文件:ThefallingofZLX.in 输出文件:ThefallingofZLX.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 正当革命如火如 ...
- 搭建TFTP服务器配置
实验内容: TFTP是TCP/IP协议族中的一个用来在客户机与服务器之间进行简单文件传输的协议,提供不复杂,开销不大的文件传输服务.TFTP承载在UDP上,提供不可靠的数据传输服务,不提供存取授权与认 ...
- 数据结构与算法分析java——线性表2(ArrarList )
ArrayList ArrayList 是一个数组队列,相当于 动态数组.与Java中的数组相比,它的容量能动态增长.它继承于AbstractList,实现了List, RandomAccess, C ...
- [译文]PHP千年虫(y2k compliance)
时钟将我们无情地逼近2000年的最后一年,第二年厄运塞耶斯都预言前所未有的电脑故障在每一个可以想象的领域.通常被称为2000年问题,或千年虫,这种 情况很容易解释.程序解释两位在形成XX日期19 XX ...
- 如何实现SQL Server临时表的创建?
以下的文章主要是对SQL Server临时表的创建的实际操作步骤,以及在实际操作中我们要用到的实际应用代码的介绍,我在一个信誉度很好的网站找到一个关于其相关内容今天拿出来供大家分享. 创建临时表 方法 ...
- Max answer(The Preliminary Contest for ICPC China Nanchang National Invitational)
Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values ...
- tarjan+topsort
题目 缩完点后统计入读为零的点就可以来. 因为缩完点后肯定是DAG #include<iostream> #include<cstdio> #include<algori ...
- Win7多用户同时登陆
软件提供下载: http://pan.baidu.com/s/1o6FQv70
- orderBy 过滤器
orderBy 过滤器根据表达式排列数组: <!DOCTYPE html><html><head><meta http-equiv="Content ...