大意: 给定$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. Flutter -------- 新手 WanAndroid 项目练习

    一个简单Flutter项目wanandroid,先前用Kotlin来开发过,适合新手练习. 用到的库 包含功能: http+数据解析 网络请求数据列表展示 Banner轮播 WebView跳转详情 D ...

  2. intel 性能分析

    分析memory bound,etc https://software.intel.com/en-us/articles/intel-vtune-amplifier-tutorials

  3. VS2015 dlib编译 x64 Release .lib生成

    VS2015 dlib编译 x64 Release >------ 已启动生成: 项目: ZERO_CHECK, 配置: Release x64 ------ > Checking Bui ...

  4. 我非要捅穿这 Neutron(二)上层资源模型篇

    目录 文章目录 目录 Neutron 的资源模型 Network 运营商网络和租户网络 创建运营商网络 创建租户网络 创建外部网络 Network 小结 Subnet IP 核心网络服务 Subnet ...

  5. django ORM 自定义字段

    class FixedCharField(models.Field): """ 自定义的char类型的字段类 """ def __init_ ...

  6. DECODE函数和CASE WHEN 比较

    http://blog.csdn.net/zhangbingtao2011/article/details/51384393 一,DECODE函数 其基本语法为: DECODE(value, if1, ...

  7. 123457123456#1#----com.ppGame.BaoBaoiMiYu35--前拼后广--miyu_pp

    com.ppGame.BaoBaoiMiYu35--前拼后广--miyu_pp

  8. 简单明了的注解,读取CLASS中的注解

    /***********注解声明***************/ /** * 水果名称注解 * @author peida * */ @Target(ElementType.FIELD) @Reten ...

  9. 推荐一款好用的 office word 的markdown插件 - Writage

    软件地址:http://www.writage.com/

  10. 【Leetcode_easy】1128. Number of Equivalent Domino Pairs

    problem 1128. Number of Equivalent Domino Pairs solution1: 不明白为什么每个元素都要加上count: class Solution { pub ...