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';
}

bzoj千题计划145:bzoj3262: 陌上花开的更多相关文章

  1. bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块

    http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...

  2. bzoj千题计划196:bzoj4826: [Hnoi2017]影魔

    http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...

  3. bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪

    http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...

  4. bzoj千题计划177:bzoj1858: [Scoi2010]序列操作

    http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...

  5. bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)

    https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...

  6. bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)

    https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...

  7. bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹

    http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...

  8. bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机

    http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...

  9. bzoj千题计划250:bzoj3670: [Noi2014]动物园

    http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...

随机推荐

  1. angularJS中$apply()方法详解

    这篇文章主要介绍了angularJS中$apply()方法详解,需要的朋友可以参考下   对于一个在前端属于纯新手的我来说,Javascript都还是一知半解,要想直接上手angular JS,遇到的 ...

  2. php htmlentities和htmlspecialchars 的区别

    很多人都以为htmlentities跟htmlspecialchars的功能是一样的,都是格式化html代码的,我以前也曾这么认为,但是今天我发现并不是这样的.   The translations ...

  3. elasticsearch6 学习之并发控制

    环境:elasticsearch6.1.2        kibana6.1.2  并发问题无处不在 一.基于_version 的并发控制 在提交数据前先检查提交数据的version与es中存储的ve ...

  4. Ubuntu终端命令--查看端口占用及关闭

    1.查看已连接的服务端口 (ESTABLISHED)     netstat-a 2.查看所有的服务端口(LISTEN,ESTABLISHED)     netstat-ap 3.查看指定端口,可以结 ...

  5. BZOJ5323 JXOI2018游戏(线性筛+组合数学)

    可以发现这个过程非常类似埃氏筛,将在该区间内没有约数的数定义为质数,那么也就是求每种方案中选完所有质数的最早时间之和. 于是先求出上述定义中的质数个数,线性筛即可.然后对每个最短时间求方案数,非常显然 ...

  6. BZOJ3244 NOI2013树的计数(概率期望)

    容易发现的一点是如果确定了每一层有哪些点,树的形态就确定了.问题变为划分bfs序. 考虑怎样划分是合法的.同一层的点在bfs序中出现顺序与dfs序中相同.对于dfs序中相邻两点依次设为x和y,y至多在 ...

  7. 【转】VS2012简单的使用感受+插件推荐

    转自:http://blog.sina.com.cn/s/blog_58c506600101b34t.html ~PS:后面有博主自己补充的VS2013的哦~ 1.Visual Studio Achi ...

  8. .NET 复制对象会影响到复制源对象

    IList<string> list=new List<string>(); list.add("a"); list.add("b"); ...

  9. 【刷题】BZOJ 4816 [Sdoi2017]数字表格

    Description Doris刚刚学习了fibonacci数列.用f[i]表示数列的第i项,那么 f[0]=0 f[1]=1 f[n]=f[n-1]+f[n-2],n>=2 Doris用老师 ...

  10. swift网络数据请求方法

    搭建一个apache服务器,用php编写一个返回给客户端请求数据的脚本 <?php // header("Content-type:text/html;charset=utf-8&qu ...