zoukankan      html  css  js  c++  java
  • loj2472 「九省联考 2018」IIIDX

    ref

    #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("
    ");
    	return 0;
    }
    
  • 相关阅读:
    在css中设置图片的背景图,怎么设置图片纵向拉伸
    css左右箭头
    在一个页面上加载另一个页面
    任务:写一个tomcat自启动脚本
    安装配置tomcat
    使用cronolog切割tomcat catalina.out文件
    使用usb+preseed在virtualbox上安装ubuntu(一)
    preseed.cfg分区设定案例
    为什么Linux的fdisk分区时第一块磁盘分区的First Sector是2048?
    zabbix 如何監控tcp的SYN,establised?
  • 原文地址:https://www.cnblogs.com/poorpool/p/9095077.html
Copyright © 2011-2022 走看看