CF Hello 2020 D. New Year and Conference //思维

题目

题意

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值