[abc309 F] Box in Box

F - Box in Box

首先,每个长方体的h,w,d都是可以任意互换的,所以我们考虑用a0,a1,a2来代替它们(a0a1a2

然后可以发现一个规律,我们肯定是用a0a0比较,a1a1比较,a2a2比较

那么现在显然就是三位偏序,可以上CDQ了,先对a0进行排序,但是因为题目要求的是严格大于,所以在CDQ时,mid不一定是取l+r2,而是一个使得mida0mid+1a0不相同的,尽量靠近中间的位置

因为若当前区间的la0ra0都相等了,我们就不用管这个区间了,所以即使我们并没有在下标上进行二分,但是我们相当于在a0的值域上进行了二分(并不是严格二分,只是一个相当于在二分的过程),所以复杂度没有问题

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5; 
int n,lsh[N],tot;
struct node{
	int a[3];
	bool operator < (const node &other)const{
		return a[0]<other.a[0];	
	}
}cn[N];
bool cmp(node a,node b){
	return a.a[1]<b.a[1];
}
map<int,int> st,ed;
int c[N];
void add(int x,int y){
	for(;x<=tot;x+=x&-x) c[x]+=y; 
}
int ask(int x){
	int ans=0;
	for(;x;x-=x&-x) ans+=c[x];
	return ans;
}
void solve(int l,int r){
	if(cn[l].a[0]==cn[r].a[0]) return;
	int mid=l+r>>1;
	if(cn[mid].a[0]==cn[mid+1].a[0]){
		int len1=st[cn[mid].a[0]]-l,len2=r-ed[cn[mid].a[0]];
		if(len1<len2) mid=ed[cn[mid].a[0]];
		else mid=st[cn[mid].a[0]]-1;
	}
	solve(l,mid),solve(mid+1,r);
	sort(cn+l,cn+mid+1,cmp),sort(cn+mid+1,cn+r+1,cmp);
	int a=l,b=mid+1;
	for(;b<=r;++b){
		while(a<=mid&&cn[a].a[1]<cn[b].a[1]) add(cn[a].a[2],1),++a;
		if(ask(cn[b].a[2]-1)){ puts("Yes"); exit(0); } 
	}
	for(int i=l;i<a;++i) add(cn[i].a[2],-1);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d%d%d",&cn[i].a[0],&cn[i].a[1],&cn[i].a[2]),sort(cn[i].a,cn[i].a+3),lsh[++tot]=cn[i].a[2];
	sort(cn+1,cn+n+1),sort(lsh+1,lsh+tot+1),tot=unique(lsh+1,lsh+tot+1)-lsh-1;
	for(int i=1;i<=n;++i){
		if(!st[cn[i].a[0]]) st[cn[i].a[0]]=i;
		ed[cn[i].a[0]]=i;
		cn[i].a[2]=lower_bound(lsh+1,lsh+tot+1,cn[i].a[2])-lsh; 
	}
	solve(1,n);
	puts("No");
	return 0;
}
posted @   LuoyuSitfitw  阅读(52)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示