BZOJ - 3262 Mo flowers

3262: Mo flowers

Time Limit: 20 Sec  Memory Limit: 256 MB
Submit: 5433  Solved: 2623
[Submit][Status][Discuss]

Description

N-flowers, each flower has three attributes: Flower (S), color (C), odor (m), represented by three integers.
Now for each flower rating, flower level is the number of flowers it has beauty can be exceeded.
A definition of a flower to another flower beautiful than B, if and only Sa> = Sb, Ca> = Cb, Ma> = Mb.
Obviously, two flowers may have the same attributes. Top statistics of the number of flowers required for each class.
 

Input

The first row N, K (1 <= N <= 100,000, 1 <= K <= 200,000), respectively, and the maximum number of flowers attribute values.
The following N lines of three integers si, ci, mi (1 <= si, ci, mi <= K), i represents the attribute flowers

Output

Contains N rows, respectively, the number indicates that the rating of each stage of flower of 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

 

Source

 First three-dimensional partial order code cdq
#include<bits/stdc++.h>
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define inf 0x3f3f3f3f
#define eps 1e-6
using namespace std;
const int maxn = 100005;
struct node{
    int x,y,z,cnt,ans;
}p[maxn];
int tree[maxn*2],k,ans[maxn];
int lowbit(int x){
    return x&(-x);
}
bool cmpx(const node u,const node v){
    if(u.x==v.x&&u.y==v.y)
            return u.z<v.z;
    if(u.x==v.x) 
        return u.y<v.y;
    return u.x<v.x;
}
bool cmpy(const node u,const node v){
      if(u.y==v.y&&u.z==v.z) 
          return u.x<v.x;
        if(u.y==v.y) 
            return u.z<v.z;
        return u.y<v.y;
}
void add(int x,int val){
    while(x<=k){
        tree[x]+=val;
        x+=lowbit(x);
    }
}
int query(int x){
    int ans=0;
    while(x){
        ans+=tree[x];
        x-=lowbit(x);
    }
    return ans;
}
void cdq(int l,int r){
    if(l==r){
        p[l].ans+=p[l].cnt-1;
        return ;
    }
    int m=(l+r)>>1;
    cdq(l,m);
    cdq(m+1,r);
    sort(p+l,p+1+m,cmpy);
    sort(p+1+m,p+1+r,cmpy);
    int j=l;
    for(int i=m+1;i<=r;i++){
        while(j<=m&&p[j].y<=p[i].y){
            add(p[j].z,p[j].cnt);
            j++;
        }
        p[i].ans+=query(p[i].z);
    }
    for(int i=l;i<j;i++)
        add(p[i].z,-p[i].cnt);
}
int main(){
    int n,tot=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d %d %d",&p[i].x,&p[i].y,&p[i].z);
        p[i].ans=1;
    }
    sort(p+1,p+1+n,cmpx);
    for(int i=1;i<=n;i++){
        if(i!=1&&p[i].x==p[i-1].x&&p[i].y==p[i-1].y&&p[i].z==p[i-1].z){
            p[tot].cnt++;
        }else {
            p[++tot]=p[i];
            p[tot].cnt=1;
        }
    }
    cdq(1,tot);
    for(int i=1;i<=tot;i++){
        ans[p[i].ans]+=p[i].cnt;
    }
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<"\n";
    }
    return 0;
}
View Code

 

 

Guess you like

Origin www.cnblogs.com/MengX/p/11184709.html