1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include <bits/stdc++.h> using namespace std; #define FO(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) #define fo(i,j,k) for(int i=(j),end_i=(k);i<=end_i;i++) #define fd(i,j,k) for(int i=(j),end_i=(k);i>=end_i;i--) #define DEBUG(x) cout<<#x<<"="<<x<<endl #define all(x) (x).begin(),(x).end() #define cle(x) memset(x,0,sizeof(x)) #define lowbit(x) ((x)&-(x)) #define ll long long #define ull unsigned ll #define db double #define lb long db #define pb push_back #define mp make_pair #define fi first #define se second inline int read() { int x=0; char ch=getchar(); bool f=0; for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1; for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch^48); return f?-x:x; } const int N=500010; int n; db k; #define lc (u<<1) #define rc (u<<1|1) #define ls lc,l,mid #define rs rc,mid+1,r int mi[N<<2],tag[N<<2]; inline void pushtag(int u,int d) { mi[u]+=d; tag[u]+=d; } inline void pushdown(int u) { if(tag[u]==0) return; pushtag(lc,tag[u]); pushtag(rc,tag[u]); tag[u]=0; } void build(int u,int l,int r) { if(l==r) {mi[u]=l,tag[u]=0; return;} int mid=l+r>>1; build(ls); build(rs); mi[u]=min(mi[lc],mi[rc]); } void add(int u,int l,int r,int L,int R,int d) { if(L<=l&&r<=R) return pushtag(u,d); pushdown(u); int mid=l+r>>1; if(L<=mid) add(ls,L,R,d); if(mid<R) add(rs,L,R,d); mi[u]=min(mi[lc],mi[rc]); } int ask(int u,int l,int r,int d) { if(l==r) return mi[u]>=d?l:l+1; pushdown(u); int mid=l+r>>1; return d<=mi[rc]?ask(ls,d):ask(rs,d); } bool bo[N]; int fa[N],d[N],siz[N],las[N],ans[N]; int main() { n=read(); scanf("%lf",&k); fo(i,1,n) d[i]=read(); sort(d+1,d+n+1,[&](const int &x,const int &y){return x>y;}); fd(i,n,1) { fa[i]=1.*i/k; ++siz[i]; siz[fa[i]]+=siz[i]; las[i]=i; if(i!=n&&d[i]==d[i+1]) las[i]=las[i+1]; } build(1,1,n); fo(i,1,n) { int u=fa[i]; if(u&&!bo[u]) bo[u]=1,add(1,1,n,ans[u],n,siz[u]-1); ans[i]=las[ask(1,1,n,siz[i])]; add(1,1,n,ans[i],n,-siz[i]); printf("%d ",d[ans[i]]); } return 0; }
|