[题目链接]

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

[算法]

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

用std :: set维护贪心

时间复杂度 : O(NlogN)

[代码]

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + ;
const int inf = 2e9; int n , m; struct info
{
int l , r , k , home;
bool type;
} a[MAXN << ]; 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 = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
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 = ; i <= n; i++)
{
int l , r;
scanf("%d%d",&l,&r);
a[i] = (info){l,r,,i,false};
}
read(m);
for (int i = ; 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 + ,a + (n + m) + ,cmp);
for (int i = ; 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\n");
return ;
}
it--;
pair< int,pair<int,int> > tmp = (*it);
s.erase(it);
ans[a[i].home] = tmp.second.second;
if (tmp.second.first > ) s.insert(make_pair(tmp.first,make_pair(tmp.second.first - ,tmp.second.second)));
it = s.find(make_pair(a[i].l,make_pair(inf,inf)));
s.erase(it);
}
}
printf("YES\n");
for (int i = ; i <= n; i++) printf("%d ",ans[i]);
printf("\n"); return ; }

[Codeforces 496E] Distributing Parts的更多相关文章

  1. codeforces 497c//Distributing Parts// Codeforces Round #283(Div. 1)

    题意:有n个区间[ai,bi],然后有n个人落在[ci,di],每个人能用ki次.问一种方式站满n个区间. 两种区间都用先x后y的升序排序.对于当前的区间[ai,bi],将ci值小于当前ai的全部放入 ...

  2. Codeforces Round #283 (Div. 2) E. Distributing Parts 贪心+set二分

    E. Distributing Parts time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Distributing Parts

    Distributing Parts 题目链接:http://codeforces.com/problemset/problem/496/E 贪心 将音乐和人都以低音升序排序,贪心处理低音更低的音乐, ...

  4. 【codeforces 496E】Distributing Parts

    [题目链接]:http://codeforces.com/contest/496/problem/E [题意] 给你n个歌曲; 每个歌曲有一个需要声音的区间li,ri; 然后给你m个人; 每个人也有一 ...

  5. codeforces 496 E. Distributing Parts(贪心+set二分)

    题目链接:http://codeforces.com/contest/496/problem/E 题意:有n场演出,每场演出都有限制的高音和低音.然后m个人给出每个人的极限高音和低音还有出场次数. 最 ...

  6. Codeforces 1006C:Three Parts of the Array(前缀和+map)

    题目链接:http://codeforces.com/problemset/problem/1006/C (CSDN又改版了,复制粘贴来过来的题目没有排版了,好难看,以后就截图+题目链接了) 题目截图 ...

  7. Codeforces Round #382 (Div. 2) D. Taxes 哥德巴赫猜想

    D. Taxes 题目链接 http://codeforces.com/contest/735/problem/D 题面 Mr. Funt now lives in a country with a ...

  8. [codeforces 241]C. Mirror Box

    [codeforces 241]C. Mirror Box 试题描述 Mirror Box is a name of a popular game in the Iranian National Am ...

  9. Codeforces Gym 100187K K. Perpetuum Mobile 构造

    K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

随机推荐

  1. LeetCode 188. Best Time to Buy and Sell Stock IV (stock problem)

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  2. 初入lambda表达式 (主要是c++11)

    写一篇不猫的博文吧 定义 lambda表达式的定义如下 [capture](parameters) mutable ->return-type{statement} 翻译成人话就是 1.[cap ...

  3. Vue页面骨架屏(一)

    在开发webapp的时候总是会受到首屏加载时间过长的影响,主流的解决方法是在载入完成之前显示loading图效果,而一些大公司会配置一套服务端渲染的架构来解决这个问题.考虑到ssr所要解决的一系列问题 ...

  4. Mvc Action可以通过jsonp方式调取

    jsonp其实是一种特殊的数据获取格式,所以在Aicton直接调取的时候肯定会出现问题,下面代码是对于jsonp调取做的处理 protected virtual ActionResult Create ...

  5. hrbust 1840 (树状数组第k大) 删点使用

    小橙子 Time Limit: 2000 MS Memory Limit: 32768 K Total Submit: 2(2 users) Total Accepted: 1(1 users) Ra ...

  6. SQL SERVER 2012 第三章 T-SQL 基本语句 group by 聚合函数

    select Name,salesPersonID From Sales.store where name between 'g' and 'j' and salespersonID > 283 ...

  7. codeforces Educational Codeforces Round 39 (Rated for Div. 2) D

    D. Timetable time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. 将windows应用程序注册为windows服务

    @echo off::设置服务名称set service_name=ServiceManagement ::设置服务描述set service_description=文件安全上传服务 ::设置服务程 ...

  9. CE310A

    http://v.ku6.com/show/tvWNTLZTVWuGVPE5ZMSUyQ...html

  10. swift container server 莫名stuck

    openstack swift container server的进程经常莫名其妙进入 D Ds等状态 记录一下这个时候 storage.error的log 便于分析 一种情形是下面这种log Jun ...