[abc309 F] Box in Box
F - Box in Box
首先,每个长方体的\(h,w,d\)都是可以任意互换的,所以我们考虑用\(a_0,a_1,a_2\)来代替它们(\(a_0\leq a_1\leq a_2\))
然后可以发现一个规律,我们肯定是用\(a_0\)和\(a_0\)比较,\(a_1\)和\(a_1\)比较,\(a_2\)和\(a_2\)比较
那么现在显然就是三位偏序,可以上\(CDQ\)了,先对\(a_0\)进行排序,但是因为题目要求的是严格大于,所以在\(CDQ\)时,\(mid\)不一定是取\(\frac{l+r}2\),而是一个使得\(mid\)的\(a_0\)和\(mid+1\)的\(a_0\)不相同的,尽量靠近中间的位置
因为若当前区间的\(l\)的\(a_0\)和\(r\)的\(a_0\)都相等了,我们就不用管这个区间了,所以即使我们并没有在下标上进行二分,但是我们相当于在\(a_0\)的值域上进行了二分(并不是严格二分,只是一个相当于在二分的过程),所以复杂度没有问题
#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;
}
[abc309 F] Box in Box的更多相关文章
- js中box和box()的区别
window.onload = function(){ var input = document.getElementByTagName('input')[0]; input.onclick = bo ...
- ABC130 Task F. Minimum Bounding Box
题目链接 题解 最小的 bounding box 一定可以在四个时间段的最左端点和最右端点之间取到. 举例言之,设四个时间段分别是 (2, 5), (7, 10), (4, 9), ( 10, 20) ...
- AtCoder Beginner Contest 130 F Minimum Bounding Box 三分法求极值(WA)
题意:给n个点的起始坐标以及他们的行走方向,每一单位时间每个点往它的方向移动一单位.问最小能包围所有点的矩形. 解法:看到题目求极值,想了想好像可以用三分法求极值,虽然我也不能证明面积是个单峰函数. ...
- win10系统在执行“ vagrant box add centos7 vagrant-centos-7.box”添加box时,报错“Vagrant failed to initialize at a very early stage: Failed to locate the powershell executable on the available PATH. ”
这个意思是:在有效的路径中未能执行PowerShell命令. 请检查PowerShell的安装和有效的路径,然后再尝试重新运行这个命令. 在环境变量path中添加powershell的路径,例如:C: ...
- [JS Compose] 0. Understand 'Box' or 'Container', they are just like Array!
We'll examine how to unnest function calls, capture assignment, and create a linear data flow with a ...
- edge box
先介绍一下matlab与c混合编程 主要步骤: 使用c语言编写函数 利用mexFunction()函数创建C与matlab接口 从Matlab中编译函数 # include <mex.h> ...
- HDU - 2475:Box(splay维护森林)
There are N boxes on the ground, which are labeled by numbers from 1 to N. The boxes are magical, th ...
- virtualbox+vagrant学习-2(command cli)-1-vagrant box命令
vagrant box 这是用于管理(添加.删除等)boxes的命令. box 是一个打包好的操作系统,是一个后缀名为 .box 的文件,其实是一个压缩包,里面包含了 Vagrant 的配置信息和 V ...
- [JS Compose] 1. Refactor imperative code to a single composed expression using Box
After understanding how Box is, then we are going to see how to use Box to refacotr code, to un-nest ...
- NOIP 模拟 box - 费用流 / 匈牙利
题目大意: 给出n(\(\le 200\))个盒子,第i个盒子长\(x_i\),宽\(y_i\),一个盒子可以放入长宽都大于等于它的盒子里,并且每个盒子里只能放入一个盒子(可以嵌套),嵌套的盒子的占地 ...
随机推荐
- 响应式编程之Project Reactor
Project Reactor作为响应式编程范式的核心实现框架,严格遵循Reactive Streams规范体系,其架构设计完整包含了规范定义的四个核心组件:Publisher(数据源).Subscr ...
- 【Ubuntu】Ubuntu 配置镜像源(ARM)
[Ubuntu]Ubuntu 配置镜像源(ARM) 零.起因 最近在QEMU中安装了个ubuntu-24.04-live-server-arm64,默认是国外的软件源,很慢,故替换到国内. 壹.替换 ...
- Oracle PLSQL 存储过程无法进入单步调试
使用PLSQL工具调试存储过程的时候,不管你怎么设置断点,当你点击测试的时候就瞬间执行而过你无法进入单步调试 解决办法:
- Oracle chr() ascii()
函数简介 实用函数 chr() 和 ascii() chr() 函数将ASCII码转换为字符: ASCII码 –> 字符: ascii() 函数将字符转换为ASCII码: 字符 –> AS ...
- HTTPS方案浅谈
付费方案 赛门铁克 沃通 其他...懒得看了,重点不是这些 免费方案 WoSign(沃通)的DV免费SSL证书: 免费SSL证书支持最多5个域名, 一次性可管2年, 到期后可免费续期,相当于永久免费. ...
- 让IE6、IE7、IE8支持CSS3的圆角、阴影样式-最好的插件
想做个页面用到css3的圆角和阴影效果,但ie浏览器不支持,之前也听说有插件可以实现,周六在网上找到了一个方法,原文如下: 但凡是前端工程师,都知道IE6,IE7,IE8不支持.或者不完全支持CSS3 ...
- where 闭包查询
$map1[] = ["like_article.user_id", 'not in', function ($query) use ($user_id) { $query-> ...
- pandas 将excle两行或多行文本合并为一行
原有excle 目的: # j加载另一份数据源 import pandas as pd import xlrd import time from xlutils.copy import copy fr ...
- Spring基于注解的事务管理
Spring基于注解的事务管理 源码 代码测试 pom.xml <?xml version="1.0" encoding="UTF-8"?> < ...
- Python基础 - 常用内置对象
数字.字符串.字节串.列表.元组.字典.集合.布尔型.空类型.异常.文件.可迭代对象.编程单元def.class.module 常量与变量 x = 3 type(x) # 查看变量类型 int typ ...