zoukankan      html  css  js  c++  java
  • bzoj3262陌上花开 cdq分治入门题

    Description 
    有n朵花,每朵花有三个属性:花形(s)、颜色(c)、气味(m),又三个整数表示。现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量。定义一朵花A比另一朵花B要美丽,当且仅当Sa>=Sb,Ca>=Cb,Ma>=Mb。显然,两朵花可能有同样的属性。需要统计出评出每个等级的花的数量。 
    Input 
    第一行为N,K (1 <= N <= 100,000, 1 <= K <= 200,000 ), 分别表示花的数量和最大属性值。 
    以下N行,每行三个整数si, ci, mi (1 <= si, ci, mi <= K),表示第i朵花的属性 
    Output 
    包含N行,分别表示评级为0…N-1的每级花的数量 
    Sample Input 

    10 3 
    3 3 3 
    2 3 3 
    2 3 1 
    3 1 1 
    3 1 2 
    1 3 1 
    1 1 2 
    1 2 2 
    1 3 2 
    1 2 1

    Sample Output 

    3 
    1 
    3 
    0 
    1 
    0 
    1 
    0 
    0 
    1

    水一发cdq分治

    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #define RG register
    #define dmax(a, b) ((a) > (b) ? (a) : (b))
    #define dmin(a, b) ((a) < (b) ? (a) : (b))
    #define gmax(i, j) ((i) < (j) ? (i = j) : (i))
    #define gmin(i, j) ((i) > (j) ? (i = j) : (i))
    #define sqr(x) ((x) * (x))
    #define dabs(x) ((x) < (0) ? (-x) : (x))
    #define lowbit(x) ((x) & (-x))
    #define For(i, a, b) for(RG int i = a, __u = b; i <= __u; i++)
    #define set_file(File) freopen(#File".in","r",stdin)
    
    const int MaxN = 100010;
    const int MaxK = 200010;
    
    struct flower{
    	int x, y, z, cnt, ans;
    }a[MaxN];
    
    bool cmpx(const flower &u, const flower &v){
    	if(u.x != v.x)return u.x < v.x;
    	if(u.y != v.y)return u.y < v.y;
    	return u.z < v.z;
    }
    
    bool cmpy(const flower &u, const flower &v){
    	if(u.y != v.y)return u.y < v.y;
    	return u.z < v.z;
    }
    
    int n, K, tot, ans[MaxN];
    
    struct BIT{
    	int c[MaxK];
    	inline void add(RG int i, RG int d){
    		for(; i <= n; i += lowbit(i))
    			c[i] += d;
    	}
    	inline int sum(RG int i){
    		RG int res=0;
    		for(; i; i -= lowbit(i))
    			res += c[i];
    		return res;
    	}
    }b;
    
    void CDQ(RG int l, RG int r){
    	if(l == r){
    		a[l].ans += a[l].cnt - 1;
    		return;
    	}
    	RG int mid = l + r >> 1;
    	CDQ(l, mid), CDQ(mid + 1, r);
    	std::sort(a + l, a + mid + 1, cmpy);
    	std::sort(a + mid + 1, a + r + 1, cmpy);
    	RG int j = l;
    	For(i, mid + 1, r){
    		for(; a[j].y <= a[i].y && j <= mid; j++)
    			b.add(a[j].z, a[j].cnt);
    		a[i].ans += b.sum(a[i].z);
    	}
    	For(i, l, j - 1) b.add(a[i].z, -a[i].cnt);
    	std::sort(a + l, a + r + 1, cmpy);
    }
    
    int main(){
    	set_file(bzoj3262);
    	scanf("%d%d", &n, &K);
    	For(i, 1, n) scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z), a[i].ans = 1;
    	std::sort(a + 1, a + 1 + n, cmpx);
    	For(i, 1, n)
    		if(i != 1 && a[i - 1].x == a[i].x && a[i - 1].y == a[i].y && a[i - 1].z == a[i].z)
    			a[tot].cnt++;
    		else
    			a[++tot] = a[i], a[tot].cnt = 1;
    	std::sort(a + 1, a + 1 + tot, cmpx);
    	CDQ(1, tot);
    	For(i, 1, tot) ans[a[i].ans] += a[i].cnt;
    	For(i, 1, n) printf("%d
    ",ans[i]);
    	return 0;
    }
    

      

  • 相关阅读:
    更改文件、图片名称思路,我们的名字在以后添加_2等待
    UIStepper使用的具体解释的控制
    ArcSDE10.1配置Oracle 监听器来使用SQL操作ST_Geometry(个人改动版)
    SDE ST_Geometry SQL st_intersects查询很慢的解决方法
    通过SQL直接插入、修改ArcGIS SDE空间表中的数据
    使用POI读写word docx文件
    Weblogic读不到Word文件
    POI写Word换行
    使用POI转换word doc文件
    POI生成Web版Word文件
  • 原文地址:https://www.cnblogs.com/keshuqi/p/6407772.html
Copyright © 2011-2022 走看看