大意: 给定$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. qemu通过控制台向虚拟机输入组合键

    ctrl+alt+2 开启控制台 ctrl+alt+1 关闭控制台 在控制台中输入 sendkey ctrl-alt-delete 发送指令

  2. Apache的Mesos/Marathon与Google的Kubernets的区别

    Apache的Mesos与Google的Kubernets的区别 – China Hadoophttp://chinahadoop.com/archives/2150 有哪些是Apache Mesos ...

  3. Mac 命令行查看自己的公网IP

    Mac 查看本机公网IP 命令 curl ifconfig.me 如果想更好看一点 curl ipinfo.io/json 还可以用wget wget http://ipecho.net/plain ...

  4. HTTP请求重复发送

    帖子地址 http://bbs.csdn.net/topics/390831787 解决方案:1.  java -Dsun.net.http.retryPost=false 2. 换用apche ht ...

  5. springboot整合mybatis的时候报错Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    今天闲来无事,学习springboot整合mybatis,在bilibili看视频学的,视频中在dao层的interface上面加上org.apache.ibatis.annotations.Mapp ...

  6. Excel对某一列的数据插入处理,域名得出IP

    早期都是通过Excel做数据统计,对某一列的数据插入处理. 代码功能是从A列纯域名,将域名转换为IP,从域名A列得到IP写到B列. 代码 #!/usr/bin/python #coding:utf-8 ...

  7. python 多线程模板简单实现

    #-*- encoding: UTF-8 -*- #编码声明 import threading,Queue,os import time #导入方法模块 def main(inargs): work_ ...

  8. 微信小程序 之页面跳转

    wxml: <view><button bindtap="abc" >跳转</button></view> js: abc: (e) ...

  9. React-native/React 公告滚动组件(原生代码)

    编写不易, 希望大家点赞 import React, {PureComponent} from 'react'; import {Animated, Easing, View} from 'react ...

  10. 根据SNP的位置从基因组提取上下游序列

      代码如下: #!/usr/bin/perl -w use strict; die "perl $0 <vcf> <genome>" if(@ARGV = ...