bzoj千题计划145:bzoj3262: 陌上花开
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: 陌上花开的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
- bzoj千题计划250:bzoj3670: [Noi2014]动物园
http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...
随机推荐
- stateful openflow------整理openstate原理以及具体应用
openstate基本思想就是控制器下放一部分功能,交换机不再是简单的dumb,而是保留一些简单的wise. 论文中以端口锁定为例,提出了米粒型状态机在交换机内部的应用从而可以大大减少交换机和控制器之 ...
- dazhewang数据库初设计
mysql> use dazhe; Database changed mysql> create table shops(id int primary key auto_increment ...
- mabatis报错 Result Maps collection already contains value for gamedataserver.dao.one.ChargeRecordMapper.BaseResultMap
1.解决这种报错看看英文"already ",也就是已经存在,其实是因为存在了两个id相同的返回,以下可以看看,根据这种例子看看自己项目是不是这种问题
- Hibernate 延迟加载 分析
出处:http://www.ibm.com/developerworks/cn/java/j-lo-hibernatelazy/#icomments Hibernate 的延迟加载(lazy load ...
- Windows服务器安全配置指南
1).系统安全基本设置 2).关闭不需要的服务 Computer Browser:维护网络计算机更新,禁用 Distributed File System: 局域网管理共享文件,不需要禁用 Distr ...
- python学习笔记05:贪吃蛇游戏代码
贪吃蛇游戏截图: 首先安装pygame,可以使用pip安装pygame: pip install pygame 运行以下代码即可: #!/usr/bin/env python import pygam ...
- Linux操作系统(三)
文件系统: boot sector:记录引导文件 sb: super block 每个文件系统只有一个sb,其余black group均是它的备份 读写文件会进入到inode operation vf ...
- 关于JEE web项目 Servlet中 “/” 的解释 ;
1.关于"/" 可以代表web应用的根目录,也可以代表站点的根目录: 1>如果交给浏览器解析,则代表web站点的根目录,如果交给web服务器解析则代表项目的根目录: 2> ...
- BZOJ3289 Mato的文件管理(莫队+树状数组)
这个做法非常显然. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib& ...
- MT【134】待定系数
已知\(a,b>0\)且\(ab(a+b)=4\),求\(2a+b\)的最小值______. 解答:\(\sqrt{3}(2a+b)\ge(\sqrt{3}+1)a+b+(\sqrt{3}-1) ...