zoukankan      html  css  js  c++  java
  • bzoj 3262: 陌上花开

    3262: 陌上花开

    Time Limit: 20 Sec  Memory Limit: 256 MB
    Submit: 2761  Solved: 1231
    [Submit][Status][Discuss]

    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

    HINT

    1 <= N <= 100,000, 1 <= K <= 200,000

    /*
        与hdu5618相类似的一道三维偏序题
        同样排序第一维,CDQ分治第二维,树状数组维护第三维
        注意相同元素的处理 
    */
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #define maxn 100010
    using namespace std;
    int n,K,tr[maxn*2],cnt[maxn];
    struct node{
        int x,y,z,ans,id;
        bool operator < (const node &p)const{
            if(x!=p.x)return x<p.x;
            if(y!=p.y)return y<p.y;
            return z<p.z;
        }
        bool operator == (const node &p)const{
            return x==p.x&&y==p.y&&z==p.z;
        }
    }q[maxn],tmp[maxn];
    void add(int x,int v){
        while(x<=K){
            tr[x]+=v;
            x+=x&(-x);
        }
    }
    int ask(int x){
        int res=0;
        while(x){
            res+=tr[x];
            x-=x&(-x);
        }
        return res;
    }
    void solve(int l,int r){
        if(l==r)return;
        int mid=(l+r)>>1;
        solve(l,mid);solve(mid+1,r);
        for(int i=l,j=l,k=mid+1;i<=r;i++){
            if((q[j].y<=q[k].y||k>r)&&j<=mid)tmp[i]=q[j++];
            else tmp[i]=q[k++];
        }
        for(int i=l;i<=r;i++){
            q[i]=tmp[i];
            if(q[i].id<=mid)add(q[i].z,1);
            else q[i].ans+=ask(q[i].z);
        }
        for(int i=l;i<=r;i++){
            if(q[i].id<=mid)add(q[i].z,-1);
        }
    }
    int main(){
        freopen("Cola.txt","r",stdin);
        scanf("%d%d",&n,&K);
        for(int i=1;i<=n;i++)
            scanf("%d%d%d",&q[i].x,&q[i].y,&q[i].z);
        sort(q+1,q+n+1);
        node q1;int te=1;
        for(int i=n;i>=1;i--){
            if(q1==q[i])q[i].ans+=te,te++;
            else q1=q[i],te=1;
        }
        for(int i=1;i<=n;i++)q[i].id=i;
        solve(1,n);
        for(int i=1;i<=n;i++)cnt[q[i].ans]++;
        for(int i=0;i<n;i++)printf("%d
    ",cnt[i]);
        return 0;
    } 
  • 相关阅读:
    IIS运行asp程序出现The requested resource is in use 和 安装.net 2.0 后运行2.0程序出现 Failed to access IIS metabase 错误的解决
    动态sql语句基本语法
    屏蔽浏览器关闭按钮及ALT+F4 快捷键
    [转]如何进行.NET高效开发
    HttpRuntime.Cache 与HttpContext.Current.Cache的疑问
    我搜集的关于工作流方面的技术文章
    [转]输入框自动完成,模仿IE的,支持FireFox
    javascript 的面向对象特性参考
    定义局部变量时,字符串不能超过8000的方法
    世联地产软件工程师笔试试题
  • 原文地址:https://www.cnblogs.com/thmyl/p/8082607.html
Copyright © 2011-2022 走看看