大意: 给定$n$个平面上互不相交的矩形. 若一个矩形区域只包含一个矩形或者它可以水平或垂直切成两块好的区域, 那么这个矩形区域是好的. 求判断整个平面区域是否是好的.

分治判断, 可以用链表实现删除元素, 或者直接用$set$

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e6+10;
struct _ {
int l,r,id;
bool operator < (const _ &rhs) const {
if (l==rhs.l) return id<rhs.id;
return l<rhs.l;
}
} a[N][4];
set<_> s[4]; int dfs(set<_> L[4]) {
if (L[0].size()<=1) return 1;
set<_> R[4];
set<_>::iterator it[4];
int m[4];
REP(i,0,3) {
it[i] = L[i].begin();
m[i] = it[i]++->r;
}
int sz = L[0].size();
REP(i,1,sz-1) REP(j,0,3) {
if (it[j]->l>=m[j]) {
for (auto t=L[j].begin(); t!=it[j]; ) {
int id = t++->id;
REP(k,0,3) R[k].insert(a[id][k]),L[k].erase(a[id][k]);
}
return dfs(L)&&dfs(R);
}
m[j] = max(m[j], it[j]++->r);
}
return 0;
} int main() {
int n=rd();
REP(i,1,n) {
int x1=rd(),y1=rd(),x2=rd(),y2=rd();
a[i][0] = {x1,x2,i};
a[i][1] = {-x2,-x1,i};
a[i][2] = {y1,y2,i};
a[i][3] = {-y2,-y1,i};
REP(j,0,3) s[j].insert(a[i][j]);
}
cout<<(dfs(s)?"YES":"NO")<<endl;
}

A Story of One Country (Hard) CodeForces - 1181E2 (分治)的更多相关文章

  1. 【Codeforces 1181E】A Story of One Country (Easy & Hard)(分治 & set)

    Description 在一个二维平面上有若干个矩形.定义一个矩形的(或有边在无限远处)区域为符合条件的条件为: 这个区域仅包含一个矩形,且不能使边界穿过任何一个矩形的内部. 这个区域可以用一个水平或 ...

  2. Pudding Monsters CodeForces - 526F (分治, 双指针)

    大意: n*n棋盘, n个点有怪兽, 求有多少边长为k的正方形内恰好有k只怪兽, 输出k=1,...,n时的答案和. 等价于给定n排列, 对于任意一个长为$k$的区间, 若最大值最小值的差恰好为k, ...

  3. Codeforces 364E 分治

    题意:给你一个01矩阵,问此矩阵有多少个和恰好为k的子矩形. 思路:分治,对于当前矩形,用一条中线把矩形分成两半,分治之后计算跨过中线的矩形个数.更具体的来说(假设划了一条水平中线),我们枚举矩形左右 ...

  4. Codeforces 1039D You Are Given a Tree [根号分治,整体二分,贪心]

    洛谷 Codeforces 根号分治真是妙啊. 思路 考虑对于单独的一个\(k\)如何计算答案. 与"赛道修建"非常相似,但那题要求边,这题要求点,所以更加简单. 在每一个点贪心地 ...

  5. 【codeforces 983E】NN country

    Description In the NN country, there are n cities, numbered from 1 to n, and n−1 roads, connecting t ...

  6. 【CodeForces】983 E. NN country 树上倍增+二维数点

    [题目]E. NN country [题意]给定n个点的树和m条链,q次询问一条链(a,b)最少被多少条给定的链覆盖.\(n,m,q \leq 2*10^5\). [算法]树上倍增+二维数点(树状数组 ...

  7. Codeforces 894.D Ralph And His Tour in Binary Country

    D. Ralph And His Tour in Binary Country time limit per test 2.5 seconds memory limit per test 512 me ...

  8. Codeforces Round #567 (Div. 2) E2 A Story of One Country (Hard)

    https://codeforces.com/contest/1181/problem/E2 想到了划分的方法跟题解一样,但是没理清楚复杂度,很难受. 看了题解觉得很有道理,还是自己太菜了. 然后直接 ...

  9. Codeforces Round #660 (Div. 2) Uncle Bogdan and Country Happiness dfs

    题目链接:Uncle Bogdan and Country Happiness 题意: t组输入,每组数据输入如下 首先一个n代表有n个城市,所有城市总人数为m,后面输入pi表示第i个城市的居住人数, ...

随机推荐

  1. win10创建Ubuntu16.04子系统,安装常用软件以及图形界面(包括win10远程桌面连接Ubuntu)

    一.开启win10子系统 [ Windows Subsystem for Linux(WSL)] 二.基本配置 三.安装常用的软件 安装配置zsh 使用 bash 客户端软件 cmder(其实是win ...

  2. rg.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:

    原先跑TEST CASE的时候没有出错 但是跑到整个程序里面,除了这个问题, 网上也找了下资料,说是用merge之类的可以解决,因为你这个update的obj和session里面的不用,所以导致此问题 ...

  3. php foreach 无法改变数组的值的问题

    转:http://www.cnblogs.com/yangwenxin/p/5845212.html 翻到PHP文档的foreach那页这样写道: “foreach 语法结构提供了遍历数组的简单方式. ...

  4. Qt--core模块概述

    QtCore模块是所有其它Qt模块的基础,包含以下核心功能: Qt Data Types:数据类型Qt Object Model:对象模型(包括元对象模型.属性系统.信号与槽机制.对象树)Input/ ...

  5. docker在windows下上传文件到容器

    我的系统是windows10,docker是用DockerToolbox工具安装的,安装完之后会默认挂载Windows的C:/Users目录,在docker里面对应路径是/c/Users,docker ...

  6. 关于微信手机端IOS系统中input输入框无法输入的问题

    如果网站不需要阻止用户的选择内容的行为就可以使用如下样式: * { -webkit-user-select: text; -user-select: text;}另一种方式: *: not(input ...

  7. zookeeper在windows的常用命令

    首先简要讲下安装 安装jdk 安装Zookeeper. 在官网http://zookeeper.apache.org/下载zookeeper.我下载的是zookeeper-3.4.6版本. 解压zoo ...

  8. 转 Java连接Oracle数据库的简单示例

    https://www.cnblogs.com/joyny/p/11176643.html https://community.oracle.com/thread/4096458 import jav ...

  9. SAP 增强篇 Method1 BADI增强的查找方法

    查找BADI的方法:(1)通过SE24,输入CL_EXITHANDLER,然后在方法GET_INSTANCE中设置断点,然后运行事务代码判断 exit_name的值,操作过程如下:输入se24,然后输 ...

  10. 【DeepCTR】

    DeepFM: https://www.jianshu.com/p/6f1c2643d31b CCPM,FGCNN: https://cloud.tencent.com/developer/artic ...