# bzoj 3262 陌上花开

 1 #include<iostream>
2 #include<cstdio>
3 #include<cmath>
4 #include<cstdlib>
5 #include<cstring>
6 #include<algorithm>
7 #include<vector>
8 #include<queue>
9 #define inf 2139062143
10 #define ll long long
11 #define MAXN 100100
12 using namespace std;
14 {
15     int x=0,f=1;char ch=getchar();
16     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
17     while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
18     return x*f;
19 }
20 int n,k,c[MAXN*2],to[MAXN],ans[MAXN],Ans[MAXN];
21 int lowbit(int x) {return x&(-x);}
22 void add(int x,int val) {for(int i=x;i<=k;i+=lowbit(i)) c[i]+=val;}
23 int query(int x) {int res=0;for(int i=x;i;i-=lowbit(i)) res+=c[i];return res;}
24 struct data
25 {
26     int x,y,z,pos,Pos;
27     bool operator != (const data &a) const
28     {
29         return x!=a.x||y!=a.y||z!=a.z;
30     }
31 }g[MAXN];
32 bool cmp1(data a,data b) {return a.x<b.x||(a.x==b.x&&a.y<b.y)||(a.x==b.x&&a.y==b.y&&a.z<b.z);}
33 bool cmp2(data a,data b) {return a.y<b.y||(a.y==b.y&&a.Pos<b.Pos);}
34 void cdq(int l,int r)
35 {
36     if(l==r) return ;
37     int mid=(l+r)>>1;
38     data m=g[mid];
39     cdq(l,mid);cdq(mid+1,r);
40     sort(g+l,g+r+1,cmp2);
41     for(int i=l;i<=r;i++)
42     {
44         else ans[g[i].pos]+=query(g[i].z);
45     }
47 }
48 int main()
49 {
51     for(int i=1;i<=n;i++)
53     sort(g+1,g+n+1,cmp1);
54     int tmp=1;g[n+1].x=k+1;
55     for(int i=1;i<=n;i++)
56     {
57         g[i].Pos=i;
58         if(g[i]!=g[i+1])
59         {
60             for(int j=tmp;j<=i;j++) to[g[j].pos]=g[i].pos;
61             tmp=i+1;
62         }
63     }
64     cdq(1,n);
65     for(int i=1;i<=n;i++) Ans[ans[to[i]]]++;
66     for(int i=0;i<n;i++) printf("%d\n",Ans[i]);
67 }
View Code

orz 一道三位偏序的原题 luogu p3810 【模板】三维偏序

posted @ 2017-12-19 14:21  jack_yyc  阅读(165)  评论(0编辑  收藏  举报