题目
题意
n个表演,每个表演在a场地需要从
[
a
s
i
,
a
e
i
]
[asi,aei]
[asi,aei]这段时间,在b场地需要从
[
b
s
i
,
b
e
i
]
[bsi,bei]
[bsi,bei]这段时间,
问是否两个表演在a冲突,在b不冲突。
思路
暴力枚举
n
2
n^2
n2复杂度
考虑按照a场地开始时间排序,不断将活动扔进优先队列,优先队列保存a中当前活动冲突的活动。
在两个multiset里维护在优先队列里的
b
s
i
bsi
bsi的最大值和
b
e
i
bei
bei的最小值,判断a冲突的活动,是不是b有不冲突的。
最后把a和b互换再求一次。
/* Author : Rshs
* Data : 2020-01-14-00.37
*/
#include<bits/stdc++.h>
using namespace std;
#define FI first
#define SE second
#define LL long long
#define MP make_pair
#define PII pair<int,int>
#define SZ(a) (int)a.size()
const double pai = acos(-1);
const double eps = 1e-10;
const LL mod = 1e9 + 7;
const int MXN = 1e6 + 5;
int n;
pair< pair<int, int>, pair<int, int> > a[MXN];
bool cmp1(pair< pair<int, int>, pair<int, int> > x, pair< pair<int, int>, pair<int, int> > y) {
return x.FI.FI < y.FI.FI;
}
struct noie {
int s, e, id;
};
bool operator<(const noie &x, const noie &y) {
return x.e > y.e;
}
int cal(){
priority_queue<noie>ie;
multiset<int>mx, mi;
sort(a + 1, a + 1 + n, cmp1);
for(int i = 1; i <= n; i++) {
while(SZ(ie) && ie.top().e < a[i].FI.FI) {
int id = ie.top().id;
ie.pop();
mx.erase(a[id].SE.FI);
mi.erase(a[id].SE.SE);
}
if(SZ(mi) && *(mi.begin()) < a[i].SE.FI) return 0;
if(SZ(mx) && *(--mx.end()) > a[i].SE.SE) return 0;
ie.push(noie{a[i].FI.FI, a[i].FI.SE, i});
mi.insert(a[i].SE.SE);
mx.insert(a[i].SE.FI);
}
return 1;
}
int main() {
cin >> n;
for(int i = 1; i <= n; i++)
scanf("%d%d%d%d", &a[i].first.first, &a[i].first.second, &a[i].second.first, &a[i].second.second);
int f=1;
f=min(f,cal());
for(int i=1;i<=n;i++){
int xx=a[i].FI.FI,yy=a[i].FI.SE;
a[i].FI.FI=a[i].SE.FI,a[i].FI.SE=a[i].SE.SE;
a[i].SE.FI=xx,a[i].SE.SE=yy;
}
f=min(f,cal());
f==1?puts("YES"):puts("NO");
return 0;
}