# Bzoj3262 陌上花开

Time Limit: 20 Sec  Memory Limit: 256 MB
Submit: 1755  Solved: 764

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

3
1
3
0
1
0
1
0
0
1

## HINT

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

CDQ分治

 1 /*by SilverN*/
2 #include<algorithm>
3 #include<iostream>
4 #include<cstring>
5 #include<cstdio>
6 #include<cmath>
7 #include<vector>
8 using namespace std;
9 const int mxn=100010;
11     int x=0,f=1;char ch=getchar();
12     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
13     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
14     return x*f;
15 }
16 struct flw{
17     int s,c,m,id,ct;
18 }f[mxn],a[mxn];
19 int ans[mxn];
20 int n,k;
21 int cmp(flw a,flw b){
22     if(a.s!=b.s)return a.s<b.s;
23     if(a.c!=b.c)return a.c<b.c;
24     return a.m<b.m;
25 }
26 int cmp1(flw a,flw b){
27     if(a.c==b.c)return a.m<b.m;
28     return a.c<b.c;
29 }
30 int t[mxn<<1];
32 int smm(int x){int res=0;while(x){res+=t[x];x-=x&-x;}return res;}
33 int cnt=0;
34 void CDQ(int l,int r){
35     if(l==r){
36 //        a[l].id+=a[l].ct-1;
37         return;
38     }
39     int i,j,mid=(l+r)>>1;
40     CDQ(l,mid);CDQ(mid+1,r);
41     sort(a+l,a+mid+1,cmp1);sort(a+mid+1,a+r+1,cmp1);
42     i=l,j=mid+1;
43     while(j<=r){
44         while(i<=mid && a[i].c<=a[j].c){
46             i++;
47         }
48         a[j].id+=smm(a[j].m);
49         j++;
50     }
52     return;
53 }
54 int main(){
55     int i,j;
57     for(i=1;i<=n;i++){
59 //        f[i].ct++;
60     }
61     sort(f+1,f+n+1,cmp);
62 /*
63     for(i=1;i<=n;i++){
64         if(f[i-1].s<=f[i].s && f[i-1].c<=f[i].c && f[i-1].m<=f[i].m){
65             a[++cnt]=f[i];
66         }
67         else a[cnt].ct++;
68     }*/
69     int tt=0;
70     for(i=1;i<=n;i++){
71         tt++;
72         if(f[i].s!=f[i+1].s || f[i].c!=f[i+1].c || f[i].m!=f[i+1].m){
73             a[++cnt]=f[i];
74             a[cnt].ct=tt;
75             tt=0;
76         }
77     }
78     CDQ(1,cnt);
79     for(i=1;i<=cnt;i++){
80         ans[a[i].id+a[i].ct-1]+=a[i].ct;
81     }
82     for(i=0;i<n;i++){
83         printf("%d\n",ans[i]);
84     }
85     return 0;
86 }

posted @ 2017-01-10 17:34  SilverNebula  阅读(175)  评论(0编辑  收藏  举报