http://www.lydsy.com/JudgeOnline/problem.php?id=3262

三维偏序

第一维排序,第二维CDQ分治,第三维树状数组

#include<cstdio>
#include<iostream>
#include<algorithm> #define lowbit(x) x&-x #define N 100001
#define M 200001 using namespace std; struct node
{
int a,b,c;
int id;
int cnt;
}e[N],L[N],R[N]; int sum[N],ans[N]; int m;
int c[M]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} bool cmp1(node p,node q)
{
if(p.a!=q.a) return p.a<q.a;
if(p.b!=q.b) return p.b<q.b;
return p.c<q.c;
} bool cmp2(node p,node q)
{
return p.b<q.b;
} void change(int x,int y)
{
while(x<=m)
{
c[x]+=y;
x+=lowbit(x);
}
} int query(int x)
{
int sum=;
while(x)
{
sum+=c[x];
x-=lowbit(x);
}
return sum;
} void solve(int l,int r)
{
if(l==r)
{
sum[e[l].id]+=e[l].cnt-;
return;
}
int mid=l+r>>;
for(int i=l;i<=mid;++i) L[i]=e[i];
for(int i=mid+;i<=r;++i) R[i]=e[i];
sort(L+l,L+mid+,cmp2);
sort(R+mid+,R+r+,cmp2);
int i=l,j=mid+;
for(;j<=r;++j)
{
while(i<=mid && L[i].b<=R[j].b)
{
change(L[i].c,L[i].cnt);
i++;
}
sum[R[j].id]+=query(R[j].c);
}
for(int k=l;k<i;++k) change(L[k].c,-L[k].cnt);
solve(l,mid);
solve(mid+,r);
} int main()
{
int n;
read(n); read(m);
for(int i=;i<=n;++i)
{
read(e[i].a);
read(e[i].b);
read(e[i].c);
}
sort(e+,e+n+,cmp1);
for(int i=;i<=n;++i) e[i].id=i;
int tot=;
for(int i=;i<=n;++i)
{
if(e[i].a!=e[i-].a || e[i].b!=e[i-].b || e[i].c!=e[i-].c)
{
e[++tot].cnt=;
e[tot].a=e[i].a;
e[tot].b=e[i].b;
e[tot].c=e[i].c;
e[tot].id=tot;
}
else e[tot].cnt++;
}
solve(,tot);
for(int i=;i<=tot;++i) ans[sum[i]]+=e[i].cnt;
for(int i=;i<n;++i) cout<<ans[i]<<'\n';
}

最新文章

  1. history命令详解
  2. DPDK编译步骤
  3. 傅里叶变换库FFTW的安装配置(VS2010)
  4. jdbc调用sparksql
  5. cyark - 数字方舟(看侣行第三季时发现的)
  6. Qt HTTP内部构架
  7. hibernate报错:org.hibernate.MappingException: No Dialect mapping for JDBC type: -1
  8. codeforces 633G. Yash And Trees dfs序+线段树+bitset
  9. c#导入excel 绑定数据 repeat为例子
  10. G1 GC技术解析
  11. yaml的用法
  12. LOJ2396 JOISC2017 长途巴士 斜率优化
  13. Linux系统挂载Windows系统下的共享文件
  14. Codeforces Round #422 (Div. 2)E. Liar sa+st表+dp
  15. Winfrom BackgroundWorker
  16. OO第三次博客
  17. Hibernate 批处理
  18. linux第七章笔记
  19. php分享十八:网页抓取
  20. iptables日志与limit参数

热门文章

  1. 进阶系列(2)—— C#集合
  2. UVA - 11021 Tribles 概率dp
  3. java 对象和基本数据类型 “==”区别
  4. 11_Java面向对象_第11天(接口、多态)_讲义
  5. IE8+SpringMVC文件上传防止JSON下载
  6. SCRUM:第一、二天任务实现情况
  7. 利用css制作带边框的小三角
  8. THREE.JS(如何想场景中添加物体对象)
  9. markdown语法---根据使用不断扩充中
  10. Powershell笔记之help about_XXX