[Codeforces 496E] Distributing Parts

Posted evenbao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Codeforces 496E] Distributing Parts相关的知识,希望对你有一定的参考价值。

[题目链接]

         https://codeforces.com/contest/496/problem/E

[算法]

        按右端点排序 , 每个乐曲优先选取的左端点最大的演奏家 

        用std :: set维护贪心

        时间复杂度 : O(NlogN)

[代码]

          

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int inf = 2e9;

int n , m;

struct info
{
        int l , r , k , home;
        bool type;
} a[MAXN << 1];

set< pair<int,pair<int,int> > > s;
int ans[MAXN];

template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == -) f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - 0;
    x *= f;
}
inline bool cmp(info a,info b) 
{ 
        if (a.r != b.r) return a.r > b.r; 
        else return a.type > b.type;
}

int main()
{
        
        read(n);
        for (int i = 1; i <= n; i++)
        {
                int l , r;
                scanf("%d%d",&l,&r);
                a[i] = (info){l,r,0,i,false};
        }
        read(m);
        for (int i = 1; i <= m; i++)
        {
                int l , r , k;
                scanf("%d%d%d",&l,&r,&k);
                a[n + i] = (info){l,r,k,i,true};
        }
        sort(a + 1,a + (n + m) + 1,cmp);
        for (int i = 1; i <= n + m; i++)
        {
                if (a[i].type)
                {
                        s.insert(make_pair(a[i].l,make_pair(a[i].k,a[i].home)));
                        continue;
                } else
                {
                        s.insert(make_pair(a[i].l,make_pair(inf,inf)));
                        set< pair<int,pair<int,int> > > :: iterator it = s.find(make_pair(a[i].l,make_pair(inf,inf)));
                        if (it == s.begin())
                        {
                                printf("NO
");
                                return 0;
                        }
                        it--;
                        pair< int,pair<int,int> > tmp = (*it);
                        s.erase(it);
                        ans[a[i].home] = tmp.second.second;
                        if (tmp.second.first > 1) s.insert(make_pair(tmp.first,make_pair(tmp.second.first - 1,tmp.second.second)));
                        it = s.find(make_pair(a[i].l,make_pair(inf,inf)));
                        s.erase(it);
                }
        }
        printf("YES
");
        for (int i = 1; i <= n; i++) printf("%d ",ans[i]);
        printf("
");
        
        return 0;
    
}

 

以上是关于[Codeforces 496E] Distributing Parts的主要内容,如果未能解决你的问题,请参考以下文章

ora-01591:锁被未分布式事物处理/Distrib tran

ubuntu17.04 调试系统工具bcc,systamtap安装

C++ 错误:预期的类成员或基类名称 ...int e、int f、string pa、string direct、string distrib):公共视频

ubuntu安装VMware tools

ubuntu安装VMware tools

linux_tools安装