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大的数,直观统计的话,会 ...
随机推荐
- Spring Cloud入门程序——注册服务提供者
1.创建Spring Starter project 2.引入依赖 点击finish 3.创建启动类 package com.hello; import org.springframework.boo ...
- 百度开源项目插件 - Echarts 图表
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 微信小程序之怎样识别一个小程序用户
本节主要是说下怎样识别一个小程序的用户,需要用什么数据来做标识呢: 我们应该都知道判断是不是一个用户大部分都是通过userid来判断,如果这个用户访问的应用发送了一个请求,把userid之类的数据发给 ...
- js 流程控制语句
1.复合语句 2.switch语句 3.do...while语句 4.while语句 5.for语句 6.for...in语句 7.break和continue语句 9.with语句 10.if语句 ...
- April 6 2017 Week 14 Thursday
If you smile when no one else is around, you really mean it. 独处时的微笑,才是发自内心的. Recently I found I seld ...
- Ruby SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B:
最近使用ruby-china的源连接不上 使用gem update遇到这个问题, 原来是ruby没有包含SSL证书,所以Https的链接被服务器拒绝. 解决方法很简单,首先在这里下载证书(http:/ ...
- soap使用xml调用webapi后返回xml信息进行JSON转换处理,以顺丰查询接口为例
expressUrl = string.Format(可以卸载配置文件的域名URL + "/bsp-oisp/ws/expressService"); StringBuilder ...
- POJ-3067 Japan---树状数组逆序对变形
题目链接: https://vjudge.net/problem/POJ-3067 题目大意: 日本岛东海岸与西海岸分别有N和M个城市,现在修高速公路连接东西海岸的城市,求交点个数. 解题思路: 记每 ...
- MapReduce计算每年最大值测试样例生成程序
Demo.java package com.java; import java.io.BufferedWriter; import java.io.File; import java.io.FileW ...
- iterm2配置项
1. 启动终端Terminal2. 进入当前用户的home目录 输入cd ~3. 创建.bash_profile 输入touch .bash_profile 在导入并应用完颜色方案之后,通 ...