【题目链接】:http://codeforces.com/contest/496/problem/E

【题意】



给你n个歌曲;

每个歌曲有一个需要声音的区间li,ri;

然后给你m个人;

每个人也有一个声音区间Li,Ri以及最多能唱的歌曲数目ki;

某个人能唱某首歌当且仅当Li<=li&&ri<=Ri

问你要如何分配这n首歌给哪些人唱

或输出无解;

【题解】



把和n+m个区间按照左端点排序;

左端点一样,就把人排在前面;

然后顺序枚举;

对于人,直接把它加入到multiset中;

(这里可以只存右端点,因为左端点没用了);

然后对于枚举到的歌;

看看multiset里面有没有人能够唱;

因为左端点肯定都比这首歌左;

所以只要看看右端点会不会比它大就好;

选哪个呢?

一定是选右端点最小的,但是在这首歌右边的人;

这样,能最大限度的利用其它人(右端点大的留在后面用,万一能唱右端点更大的歌的呢);

选定某个人之后,他能唱的歌数递减;

如果他已经不能唱歌了,就把它从multiset中取出来;

multiset的重载函数最好这样写,那个friend bool operator 老是出问题

    bool operator < (const node & temp)const{
return r<temp.r;
}

【Number Of WA】



1



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2e5+100; struct abc{
int l,r;
int flag,num,id;
}; struct abc1{
int l,r,num,id;
bool operator < (const abc1& tmp)const{
return r<tmp.r;
}
}; int n,m,ans[N],num[N];
abc a[N];
multiset <abc1> dic; void out(){
cout << "NO" <<endl;
exit(0);
} bool cmp(abc a,abc b){
if (a.l!=b.l)
return a.l < b.l;
else
return a.flag > b.flag;
} int main(){
//Open();
Close();
cin >> n;
rep1(i,1,n){
cin >> a[i].l >> a[i].r;
a[i].flag = 0,a[i].id = i;
}
cin >> m;
rep1(i,n+1,n+m){
cin >> a[i].l >> a[i].r >> num[i-n];
a[i].flag = 1,a[i].id = i-n;
}
sort(a+1,a+1+n+m,cmp);
rep1(i,1,n+m){
abc1 temp;
temp.l = a[i].l,temp.r = a[i].r,temp.id = a[i].id;
if (a[i].flag ==0){
if (dic.empty()) out();
multiset <abc1>::iterator t = dic.lower_bound(temp);
if (t == dic.end()) out();
ans[a[i].id] = t->id;
num[t->id]--;
if (!num[t->id]) dic.erase(t);
}else {
dic.insert(temp);
}
}
cout <<"YES"<<endl;
rep1(i,1,n) cout << ans[i] <<' ';
return 0;
}

【codeforces 496E】Distributing Parts的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【55.70%】【codeforces 557A】Ilya and Diplomas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【codeforces 754A】Lesha and array splitting

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 750D】New Year and Fireworks

    time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...

  5. 【codeforces 750B】New Year and North Pole

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  7. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  8. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  9. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

随机推荐

  1. Mysql干货收集

    mysql优化:https://www.cnblogs.com/duanxz/tag/mysql/default.html?page=1

  2. c 最简单的链表

    #include <stdio.h> struct node { int data; struct node *next; //指向本身的指针 }; // main() { struct ...

  3. pytorch 7 save_reload 保存和提取神经网络

    import torch import matplotlib.pyplot as plt # torch.manual_seed(1) # reproducible # fake data x = t ...

  4. 11g,12c Oracle Rac安装

    安装 Oracle 12cR1 RAC on Linux 7 本文介绍如何在Oracle Linux 7上安装2节点Oracle 12cR1 Real Application Cluster(RAC) ...

  5. 【codeforces 743E】Vladik and cards

    [题目链接]:http://codeforces.com/problemset/problem/743/E [题意] 给你n个数字; 这些数字都是1到8范围内的整数; 然后让你从中选出一个最长的子列; ...

  6. 在对Activity基类的封装中,我做了什么

    在开发实践中,不同Activity有很多代码是反复冗余的.因此非常有必要将这部分抽取出来.封装一个继承自Activity的类,命名为BaseActivity. 翻看之前写过的代码,起初,BaseAct ...

  7. 【转载】SQLITE3 使用总结

    转载自网友董淳光的文章. 前序: 这里要注明,我是一个跨平台专注者,并不喜欢只用 windows 平台.我以前的工作就是为 unix 平台写代码.下面我所写的东西,虽然没有验证,但是我已尽量不使用任何 ...

  8. 随心所欲生成git仓库随意一段commit的专用patch应用小实践

     随心所欲生成git仓库随意一段commit的专用patch应用小实践 我们在开发中.时不时的可能要去做一个patch给你的下线,或者你的合作者.在git管理中,我们知道有git format-pat ...

  9. 怎样用批处理来执行多个exe文件

    怎样用批处理来运行多个exe文件 @echo off start *****.exe start *****.exe start *****.exe start *****.exe 接着我们就能够运行 ...

  10. Eclipse 更新Android SDK后,新建项目出现appcompat_v7project的相关问题

    Eclipse 更新Android SDK后,新建项目出现各种问题.网上各种解决方式,搞了好久,总结一下. 1.出现error: Error retrieving parent for item: N ...