[题目链接]

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. python3.x Day6 socketserver

    socketserver是啥? 简化了编写网络服务器,就是对于socket的再一次封装sockerserver包含4个类可以使用:A=socketserver.TCPServer() #用于TCP/I ...

  2. Python之面向对象上下文管理协议

    Python之面向对象上下文管理协议 析构函数: import time class Open: def __init__(self,filepath,mode='r',encode='utf-8') ...

  3. Uva 12657 移动盒子(双向链表)

    题意: 你有一行盒子,从左到右依次编号为1, 2, 3,…, n.可以执行以下4种指令:1 X Y表示把盒子X移动到盒子Y左边(如果X已经在Y的左边则忽略此指令).2 X Y表示把盒子X移动到盒子Y右 ...

  4. 【】node基础概念问题(转载)

    1.nodejs编写HelloWord,了解什么是nodejs,nodejs有什么特点   2.nodejs的模块怎么用,如何载入别的模块(require),如何给另一模块调用(module, mod ...

  5. 【02】AMD、CMD、UMD 模块的写法

    AMD.CMD.UMD 模块的写法 简介 最近几年,我们可以选择的Javascript组件的生态系统一直在稳步增长.虽然陡增的选择范围是极好的,但当组件混合匹配使用时就会出现很尴尬的局面.开发新手们会 ...

  6. jQuery_DOM学习之------创建节点及节点属性

    DOM创建节点及节点属性 一.创建新的节点并添加到dom中 dom 节点创建的过程(创建节点<元素.属性.文本等>.添加节点的属性.加入到文档中) jQuery创建元素节点的方法: 创建元 ...

  7. KNN-K近邻算法(1)

    KNN(K-nearest neighbors) 思想简单 数学所需知识少(近零) 效果好 可解释机器学习算法使用过程中的很多细节问题 更完整的刻画机器学习应用的流程 天然可解决多分类问题 可解决回归 ...

  8. HDU 2897 经典巴什博弈

    从n个石子中每次取p~q个,求先手能否获胜 可以先列举一部分数据,然后观察可得总是在p+q中循环,所以只要用n对p+q取模就好了 #include <cstdio> #include &l ...

  9. 餐巾(cogs 461)

    [问题描述] 一个餐厅在相继的N天里,第i天需要Ri块餐巾(i=l,2,…,N).餐厅可以从三种途径获得餐巾. (1)购买新的餐巾,每块需p分: (2)把用过的餐巾送到快洗部,洗一块需m天,费用需f分 ...

  10. 在windows下安装Django

    2013-07-24 21:23:30| 1.安装Python 我安装的是Python(x,y)-2.7.5.0,安装目录在C盘.安装成功后如下图所示.   2.安装Django 从https://w ...