[题目链接]

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. linux netstat-查看Linux中网络系统状态信息

    博主推荐:更多网络测试相关命令关注 网络测试  收藏linux命令大全 netstat命令用来打印Linux中网络系统的状态信息,可让你得知整个Linux系统的网络情况. 语法 netstat(选项) ...

  2. python TCP协议与UDP协议

    1. TCP协议 / UDP协议 1.1 TCP协议 1.可靠.慢.全双工通信 2.建立连接的时候 : 三次握手 3.断开连接的时候 : 四次挥手 4.在建立起连接之后 发送的每一条信息都有回执 为了 ...

  3. Django-rest_framework中利用jwt登录验证时,自定义返回凭证和登录校验支持手机号

    安装 pip install djangorestframework-jwt 在Django.settings中配置 REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATIO ...

  4. Pycharm下GitHub配置使用

    1.下载并安装git 要连接GitHub,首先git是必不可少的,git的安装的基本使用很简单,这里略过.. 2.如图所示,进入Pycharm的Setting>>> Version ...

  5. PHP学习笔记<参数的传递>

    简单的例子说明参数在PHP文件之间的传递(有两个PHP文件在index.php文件上点击链接,在跳转的时候,依据参数的不同在neirong.php文件中显示不同的内容) inde.php的内容如下: ...

  6. BNUOJ 5997 Fibonacci again and again

    Fibonacci again and again Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HD ...

  7. Codeforces Round #261 (Div. 2) E (DP)

    E. Pashmak and Graph Pashmak's homework is a problem about graphs. Although he always tries to do hi ...

  8. Delphi:Indy9的IdFTP完全使用

    Delphi 7自带的INDY控件,其中包含了IdFTP,可以方便的实现FTP客户端程序,参考自带的例子,其中有上传.下载.删除文件,但是不包含对文件夹的操作,得自己实现上传.下载.删除整个文件夹(带 ...

  9. [bzoj4826][Hnoi2017]影魔_单调栈_主席树

    影魔 bzoj-4826 Hnoi-2017 题目大意:给定一个$n$个数的序列$a$,求满足一下情况的点对个数: 注释:$1\le n,m\le 2\cdot 10^5$,$1\le p1,p2\l ...

  10. [bzo1211][HNOI2004]树的计数_prufer序列

    树的计数 bzoj-1211 HNOI-2004 题目大意:题目链接. 注释:略. 想法: prufer序列有一个性质就是一个数在prufer序列中出现的次数等于这个prufer序列生成的树中它的度数 ...