= =原来复杂度还是nlog^2(n) Orz 被喷了

 #include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std; const int D=3e6;
char in[D],*I=in,out[D],*O=out; inline int gint(){
int x=;for(;*I<||*I>;++I);
for(;*I>&&*I<;++I)x=*x+*I-;
return x;
} inline void print(int x){
char tmp[],*t=tmp;
if(!x)*t++=;
for(;x;x/=)*t++=x%+;
for(;t--!=tmp;*O++=*t);
*O++='\n';
} const int Maxn= + ;
int C[Maxn*],ans[Maxn],N,K,n=;
struct Node{
int a,b,c,s,ans;
inline bool operator==(const Node&rhs)const{
return a==rhs.a&&b==rhs.b&&c==rhs.c;
}
inline bool operator!=(const Node&rhs)const{
return !(*this==rhs);
}
void init(){a=gint(),b=gint(),c=gint();}
}p[Maxn],q[Maxn]; inline void Add(int x,const int&y){
for(;<x&&x<=K;x+=x&-x)C[x]+=y;
}
inline int Query(int x){
int ret=;
for(;<x&&x<=K;x-=x&-x)ret+=C[x];
return ret;
}
inline bool cmp1(const Node&x,const Node&y){
if(x.a!=y.a)return x.a<y.a;
if(x.b!=y.b)return x.b<y.b;
return x.c<y.c;
}
inline bool cmp2(const Node&x,const Node&y){
if(x.b!=y.b)return x.b<y.b;
return x.c<y.c;
}
void CDQ(int l,int r){
if(l==r)return;
int mid=(l+r)>>;
CDQ(l,mid);CDQ(mid+,r); int i=l;
for(int j=mid+;j<=r;j++){
for(;i<=mid&&p[i].b<=p[j].b;i++)
Add(p[i].c,p[i].s);
p[j].ans+=Query(p[j].c);
}
for(int j=l;j<i;j++)Add(p[j].c,-p[j].s);
merge(p+l,p+mid+,p+mid+,p+r+,q,cmp2);
memcpy(p+l,q,sizeof(p[])*(r-l+));
}
void init(){
N=gint(),K=gint();
for(int i=;i<=N;i++)q[i].init();
sort(q+,q+N+,cmp1);
for(int cnt=,i=;i<=N;i++,cnt++){
if(q[i]!=q[i+]){p[++n]=q[i];p[n].s=cnt;cnt=;}
}
}
int main(){
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout); fread(I,,D,stdin); init();
CDQ(,n); for(int i=;i<=n;i++)ans[p[i].ans+p[i].s-]+=p[i].s;
for(int i=;i<N;i++)print(ans[i]); *--O=; return puts(out),;
}

BZOJ 3262 陌上花开 CDQ分治的更多相关文章

  1. bzoj 3262 陌上花开 - CDQ分治 - 树状数组

    Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当 ...

  2. BZOJ 3262: 陌上花开 [CDQ分治 三维偏序]

    Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当 ...

  3. BZOJ 3262 陌上花开 ——CDQ分治

    [题目分析] 多维问题,我们可以按照其中一维排序,然后把这一维抽象的改为时间. 然后剩下两维,就像简单题那样,排序一维,树状数组一维,按照时间分治即可. 挺有套路的一种算法. 时间的抽象很巧妙. 同种 ...

  4. BZOJ 3262: 陌上花开 (cdq分治,三维偏序)

    #include <iostream> #include <stdio.h> #include <algorithm> using namespace std; c ...

  5. BZOJ 3262: 陌上花开 CDQ

    这个题大部分人用了离散然后水之,然而.....作为一只蒟蒻我并没有想到离散,而是直接拿两个区间一个对应n,一个对应k来搞,当然这两个区间是对应的,我把第一维排序,第二维CDQ,第三维树状数组,然而由于 ...

  6. [BZOJ 3456]城市规划(cdq分治+FFT)

    [BZOJ 3456]城市规划(cdq分治+FFT) 题面 求有标号n个点无向连通图数目. 分析 设\(f(i)\)表示\(i\)个点组成的无向连通图数量,\(g(i)\)表示\(i\)个点的图的数量 ...

  7. [BZOJ 2989]数列(CDQ 分治+曼哈顿距离与切比雪夫距离的转化)

    [BZOJ 2989]数列(CDQ 分治) 题面 给定一个长度为n的正整数数列a[i]. 定义2个位置的graze值为两者位置差与数值差的和,即graze(x,y)=|x-y|+|a[x]-a[y]| ...

  8. P3810 陌上花开 CDQ分治

    陌上花开 CDQ分治 传送门:https://www.luogu.org/problemnew/show/P3810 题意: \[ 有n 个元素,第 i 个元素有 a_i. b_i. c_i 三个属性 ...

  9. Luogu 3810 & BZOJ 3262 陌上花开/三维偏序 | CDQ分治

    Luogu 3810 & BZOJ 3263 陌上花开/三维偏序 | CDQ分治 题面 \(n\)个元素,每个元素有三个值:\(a_i\), \(b_i\) 和 \(c_i\).定义一个元素的 ...

随机推荐

  1. sublime text3-代码片段配置

    1.Tools->New Snippet-> <snippet>     <content><![CDATA[${1:public }function ${2 ...

  2. mysql update from 子查询

    mssql 子查询更新 update log set uin= b.uinfrom log a,logs bwhere a.accountuin = b.accountuin mysql 不支持 up ...

  3. 【关于JavaScript】自动计算的实例

    在一些贸易业务Web系统中,某些页面需要提供实时的辅助计算功能,例如:员工录入货物的单价和数量的值,通过JavaScript的事件处理可以直接显示出总价. 如下图所示就是本例的运行效果图: 本例中也采 ...

  4. HashMap遍历,推荐使用entrySet()

    之前map遍历,偶尔会先去keyset然后再遍历keyset 比如 Map map = new HashMap(); Iterator it = map.keySet().iterator(); wh ...

  5. bzoj 3505: [Cqoi2014]数三角形 组合数学

    3505: [Cqoi2014]数三角形 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 478  Solved: 293[Submit][Status ...

  6. [CF Round #294 div2] D. A and B and Interesting Substrings 【Map】

    题目链接:D. A and B and Interesting Substrings 题目大意 给定26个小写字母的权值,一共26个整数(有正有负). 给定一个小写字母组成的字符串(长度10^5),求 ...

  7. strong ,weak

    有时我们写个代码开源出来给别人用时,会被其他开发者抱怨编译不了,很多情况是版本的问题,尤其现在ARC的出现后关于weak,strong的问题让人头疼.有个开源代码这里做的很不错,就是MBProgres ...

  8. prototype.js 源码解读(01)

    prototype.js是一个设计的非常优雅且很有实用价值的js基础类库,其源码非常值得研究.研究它的源码不仅能提升个人水平,而且对你打下坚实的js基础也很有帮助.因本人技术水平有限,该解读仅供参考. ...

  9. JPA2.1 中三个提升应用性能的新功能

    经常在网上看到开发者们抱怨 JPA 性能低下的帖子或文章,但如果仔细查看这些性能问题,常会发现导致问题的根本原因大致包括以下几个: 使用过多的 SQL 查询从数据库中获取所需的实体信息,即我们常说的n ...

  10. c#回调函数写法

    添加一个cs文件,在里面定义回调 using System; using System.Collections.Generic; using System.Linq; using System.Web ...