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

    3262: 陌上花开

    Time Limit: 20 Sec  Memory Limit: 256 MB
    Submit: 2590  Solved: 1159
    [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

    Source

    树套树 CDQ分治

    很裸的CDQ分治

    对于第一维排序,第二维cdq,第三维树状数组搞掉

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    inline int read(){
        int x=0;int f=1;char ch=getchar();
        while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
        while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    const int MAXN=2e6+10;
    struct node{
        int sum,ine,a,b,c;
    }e[MAXN],q[MAXN];
    int cc[MAXN<<1]={},ans[MAXN];
    inline int lowbit(int x){
        return x&-x;
    }
    inline void insert(int x,int vv){
        while(x<4000000){
            cc[x]+=vv;
            x+=lowbit(x);
        }
    }
    inline int search(int xx){
        int ans=0;
        while(xx){
            ans+=cc[xx];
            xx-=lowbit(xx);
        }
        return ans;
    }
    inline bool mycmp(node x,node y){
        if(x.a==y.a){
            if(x.b==y.b){
                return x.c<y.c;
            }
            return x.b<y.b;
        }
        return x.a<y.a;
    }
    inline bool mycmpp(node x,node y){
        return (x.b==y.b)?x.c<y.c:x.b<y.b;
    }
    inline void cdq(int l,int r){
        if(l==r) return;
        int mid=(l+r)>>1;
        cdq(l,mid);cdq(mid+1,r);
        sort(e+l,e+mid+1,mycmpp);sort(e+mid+1,e+r+1,mycmpp);
        int l1=l;int l2=mid+1;
        while(l2<=r){
            while(l1<=mid&&e[l1].b<=e[l2].b){
                insert(e[l1].c,e[l1].sum);
                l1++;
            }
            e[l2].ine+=search(e[l2].c);
            l2++;
        }
        for(int i=l;i<=l1-1;i++){
            insert(e[i].c,-e[i].sum);
        }
    }
    int main(){
        //freopen("All.in","r",stdin);
        //freopen("zhang.out","w",stdout);
        int n=read();int m=read();
        int k=0;int cnt=0;
        for(int i=1;i<=n;i++){
            q[i].a=read();q[i].b=read();q[i].c=read();
        }
        sort(q+1,q+n+1,mycmp);
        for(int i=1;i<=n;i++){
            cnt++;
            if(q[i].a!=q[i+1].a||q[i].b!=q[i+1].b||q[i].c!=q[i+1].c){
                e[++k]=q[i];
                e[k].sum=cnt;
                cnt=0;
            }
        }
        cdq(1,k);
        for(int i=1;i<=k;i++){
            ans[e[i].sum+e[i].ine-1]+=e[i].sum;
        }
        for(int i=0;i<n;i++){
            printf("%d
    ",ans[i]);
        }
        return 0;
    }
    

     对拍代码

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    inline int read(){
        int x=0;int f=1;char ch=getchar();
        while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
        while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int main(){
        freopen("All.in","w",stdout);
        srand(int(time(NULL)));
        int n=rand()%100007+1;int m=rand()%1007+1;
        cout<<n<<' '<<m<<endl;
        for(int i=1;i<=n;i++){
            printf("%d %d %d
    ",rand()%m+1,rand()%m+1,rand()%m+1);
        }
        return 0;
    }
    
  • 相关阅读:
    phpstorm常用快捷键
    tp3.2.3运用phpexcel将excel文件导入mysql数据库
    TP3.2加载外部PHPexcel类,实现导入和导出
    Navicat常用快捷键
    thnkphp框架面试问题
    PHPSQL注入
    PHP4个载入语句的区别
    goflyway简单使用
    ubuntu16.04 HyperLedger Fabric 1.2.0 开发环境搭建
    DApp demo之pet-shop
  • 原文地址:https://www.cnblogs.com/something-for-nothing/p/7884155.html
Copyright © 2011-2022 走看看