考虑不断暴力用bfs地拆, 复杂度 n ^ 2 * log(n), 1e5复杂度的不知道怎么做啊。。
#include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x) ((int)x.size()) #define ALL(x) (x).begin(), (x).end() #define fio ios::sync_with_stdio(false); cin.tie(0); using namespace std; const int N = 1e5 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 998244353; const double eps = 1e-8; const double PI = acos(-1); template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;} template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;} template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;} template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;} int n; struct Node { int a, b, c, d; void read() { scanf("%d%d%d%d", &a, &c, &b, &d); } void print() { printf("%d %d %d %d ^^ ", a, b, c, d); } }; queue<vector<Node>> que; vector<Node> now, tmpL, tmpR; bool cmpa(const Node &x, const Node &y) { return x.a < y.a; } bool cmpb(const Node &x, const Node &y) { return x.c < y.c; } bool solve() { sort(ALL(now), cmpa); int maxB = now[0].b; for(int i = 1; i < SZ(now); i++) { if(now[i].a >= maxB) { tmpL.clear(); tmpR.clear(); for(int j = 0; j < i; j++) tmpL.push_back(now[j]); for(int j = i; j < SZ(now); j++) tmpR.push_back(now[j]); que.push(tmpL); que.push(tmpR); return true; } else chkmax(maxB, now[i].b); } sort(ALL(now), cmpb); int maxD = now[0].d; for(int i = 1; i < SZ(now); i++) { if(now[i].c >= maxD) { tmpL.clear(); tmpR.clear(); for(int j = 0; j < i; j++) tmpL.push_back(now[j]); for(int j = i; j < SZ(now); j++) tmpR.push_back(now[j]); que.push(tmpL); que.push(tmpR); return true; } else chkmax(maxD, now[i].d); } return false; } int main() { scanf("%d", &n); vector<Node> a(n); for(int i = 0; i < n; i++) a[i].read(); que.push(a); while(!que.empty()) { now = que.front(); que.pop(); if(SZ(now) == 1) continue; if(!solve()) { puts("NO"); return 0; } } puts("YES"); return 0; } /* */