[abc309 F] Box in Box
F - Box in Box
首先,每个长方体的
然后可以发现一个规律,我们肯定是用
那么现在显然就是三位偏序,可以上
因为若当前区间的
#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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!