陌上花开(bzoj 3262)
Description
Input
Output
Sample Input
3 3 3
2 3 3
2 3 1
3 1 1
3 1 2
1 3 1
1 1 2
1 2 2
1 3 2
1 2 1
Sample Output
1
3
0
1
0
1
0
0
1
HINT
1 <= N <= 100,000, 1 <= K <= 200,000
/*
这个东西好像叫三维偏序,就是排序一维,cdq一维,树状数组一维。
自己尝试码了码,但是出现了很多问题,然后看了看网上的代码,感觉还是不怎么懂
*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#define N 500010
using namespace std;
int now,n,ans[N],k;
struct node{
int c,s,m,num,ans;
};node a[N],b[N],q[N];
struct Node{
int v,T;
};Node t[N*];
bool cmp(node a,node b){
if(a.s==b.s&&a.c==b.c)return a.m<b.m;
if(a.s==b.s)return a.c<b.c;
return a.s<b.s;
}
bool cmp2(node a,node b){
if(a.c==b.c&&a.s==b.s)return a.m<b.m;
if(a.c==b.c)return a.s<b.s;
return a.c<b.c;
}
void modify(int x,int v){
while(x<=k){
if(t[x].T==now) t[x].v+=v;
else t[x].T=now,t[x].v=v;
x+=x&(-x);
}
}
int query(int x){
int sum=;
while(x){
if(t[x].T==now)sum+=t[x].v;
x-=x&(-x);
}
return sum;
}
void cdq(int l,int r){
if(l==r){
a[l].ans+=(a[l].num-);
return;
}
int m=l+r>>;
int q1=l,q2=m+;
for(int i=l;i<=r;i++)
if(q1<=m&&a[i].s<=m)
q[q1++]=a[i];
else q[q2++]=a[i];
for(int i=l;i<=r;i++)
a[i]=q[i];
cdq(l,m);
now++;
int j=l;
for(int i=m+;i<=r;i++){
for(;j<=m;j++)
if(a[i].c>=a[j].c)modify(a[j].m,a[j].num);
else break;
a[i].ans+=query(a[i].m);
}
cdq(m+,r);
q1=l;q2=m+;
for(int i=l;i<=r;i++)
if((a[q1].c<=a[q2].c||q2>r)&&q1<=m)
q[i]=a[q1++];
else q[i]=a[q2++];
for(int i=l;i<=r;i++)
a[i]=q[i];
}
int main(){
now=;
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
scanf("%d%d%d",&a[i].s,&a[i].c,&a[i].m);
a[i].num=;
}
sort(a+,a+n+,cmp);
int tot=;
for(int i=;i<=n;i++){
int k=(a[i].s==a[i-].s)&(a[i].c==a[i-].c)&(a [i].m==a[i-].m);
if(i==||!k)a[++tot]=a[i];
else a[tot].num++;
}
for(int i=;i<=tot;i++)a[i].s=i;
sort(a+,a+tot+,cmp2);
cdq(,tot);
for(int i=;i<=tot;i++)
ans[a[i].ans]+=a[i].num;
for(int i=;i<n;i++)
printf("%d\n",ans[i]);
return ; }
陌上花开(bzoj 3262)的更多相关文章
- 陌上花开 HYSBZ - 3262 (CDQ分治)
陌上花开 HYSBZ - 3262 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),用三个整数表示. 现在要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量. 定义一朵花A比另 ...
- bzoj 3262 陌上花开 - CDQ分治 - 树状数组
Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当 ...
- Luogu 3810 & BZOJ 3262 陌上花开/三维偏序 | CDQ分治
Luogu 3810 & BZOJ 3263 陌上花开/三维偏序 | CDQ分治 题面 \(n\)个元素,每个元素有三个值:\(a_i\), \(b_i\) 和 \(c_i\).定义一个元素的 ...
- 【BZOJ 3262】 3262: 陌上花开 (CDQ分治)
3262: 陌上花开 Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A ...
- BZOJ.3262.陌上花开([模板]CDQ分治 三维偏序)
题目链接 BZOJ3262 洛谷P3810 /* 5904kb 872ms 对于相邻x,y,z相同的元素要进行去重,并记录次数算入贡献(它们之间产生的答案是一样的,但不去重会..) */ #inclu ...
- BZOJ 3262 陌上花开 ——CDQ分治
[题目分析] 多维问题,我们可以按照其中一维排序,然后把这一维抽象的改为时间. 然后剩下两维,就像简单题那样,排序一维,树状数组一维,按照时间分治即可. 挺有套路的一种算法. 时间的抽象很巧妙. 同种 ...
- bzoj 3262 陌上花开
本质是一个三维偏序,一位排序后cdq分治,一维在子函数里排序,一维用树状数组维护. 把三维相等的合并到一个里面. #include<iostream> #include<cstdio ...
- BZOJ 3262 陌上花开 CDQ分治
= =原来复杂度还是nlog^2(n) Orz 被喷了 #include<cstdio> #include<cstdlib> #include<algorithm> ...
- BZOJ 3262: 陌上花开 [CDQ分治 三维偏序]
Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当 ...
- 【刷题】BZOJ 3262 陌上花开
Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),用三个整数表示. 现在要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量. 定义一朵花A比另一朵花B要美 ...
随机推荐
- bzip2命令
bzip2命令——压缩文件 命令所在路径:/usr/bin/bzip2 示例1: # bzip2 yum.log 压缩当前目录下yum.log文件成yum.log.bz2 示例2: # bzip2 - ...
- ubuntu 14.04 安装tomcat服务器 配置图片路径和文件路径
root@hett-PowerEdge-T30:/usr/local/src# lltotal 235956drwxr-xr-x 6 root root 4096 3月 26 14:48 ...
- 反射机制与IOC容器
原文地址:http://blog.csdn.net/u010926964/article/details/47262771
- KTU Programming Camp (Winter Training Day 1)
A.B.C(By musashiheart) 0216个人赛前三道题解 E(By ggg) Gym - 100735E Restore H(by pipixia) Gym - 100735H
- Python 基础-3
使用while打印1 2 3 4 5 6 8 9 10 count = 0 #while count < 10: while count < 10: count += 1 if co ...
- 美可能排除中国大陆制造/生产的所有5G产品
https://www.wsj.com/articles/u-s-considers-requiring-5g-equipment-for-domestic-use-be-made-outside-c ...
- Bootstrap 原始按钮
Bootstrap 原始按钮 <!DOCTYPE html><html><head><meta http-equiv="Content-Type&q ...
- ios多线程NSThread
1.简介: 1.1 iOS有三种多线程编程的技术,分别是: 1..NSThread 2.Cocoa NSOperation (iOS多线程编程之NSOperation和NSOperationQueue ...
- app内嵌H5调用分享
最近产品提出了一个需求:我们在合作方的app中提供的部分页面中增加分享页面,具体要求是在3个二维码推广页面调用app的分享接口,分享方式有3种,分别是点击”分享链接“按钮调起分享,点击”分享图片“按钮 ...
- 【贪心】「poj1328」Radar Installation
建模:二维转一维:贪心 Description Assume the coasting is an infinite straight line. Land is in one side of coa ...