CF 496E

E. Distributing Parts

You are an assistant director in a new musical play. The play consists of n musical parts, each part must be performed by exactly one actor. After the casting the director chose m actors who can take part in the play. Your task is to assign the parts to actors. However, there are several limitations.

First, each actor has a certain voice range and there are some parts that he cannot sing. Formally, there are two integers for each actor, ci and di (ci ≤ di) — the pitch of the lowest and the highest note that the actor can sing. There also are two integers for each part — aj and bj (aj ≤ bj) — the pitch of the lowest and the highest notes that are present in the part. The i-th actor can perform the j-th part if and only if ci ≤ aj ≤ bj ≤ di, i.e. each note of the part is in the actor‘s voice range.

According to the contract, the i-th actor can perform at most ki parts. Besides, you are allowed not to give any part to some actors (then they take part in crowd scenes).

The rehearsal starts in two hours and you need to do the assignment quickly!

Input

The first line contains a single integer n — the number of parts in the play (1 ≤ n ≤ 105).

Next n lines contain two space-separated integers each, aj and bj — the range of notes for the j-th part (1 ≤ aj ≤ bj ≤ 109).

The next line contains a single integer m — the number of actors (1 ≤ m ≤ 105).

Next m lines contain three space-separated integers each, ci, di and ki — the range of the i-th actor and the number of parts that he can perform (1 ≤ ci ≤ di ≤ 109, 1 ≤ ki ≤ 109).

Output

If there is an assignment that meets all the criteria aboce, print a single word "YES" (without the quotes) in the first line.

In the next line print n space-separated integers. The i-th integer should be the number of the actor who should perform the i-th part. If there are multiple correct assignments, print any of them.

If there is no correct assignment, print a single word "NO" (without the quotes).

大意:

一出戏有 n 幕, m 位演员, 每位演员有一个音域, 每幕都有声音的上下界, 一个演员能表演这一幕(一幕只有一个演员表演)当且仅当这个演员的音域能完全覆盖这一幕的音域....

每位演员最多只能演 k 幕, 问是否存在一种方案,使得整出戏都有人表演.输出方案.

思路:

比较好的贪心....

刚开始的想法是先选,不行就从前面进行"撤销操作"....发现根本写不出...

后来无奈看题解..... 恍然大悟...

将演员和每一幕的音域混合排序... 由于 l 是递增的,所以只要从以前的演员中找出一个最接近这个即可,为什么这个最优呢?

因为这个最矮,所以高的能留给后面,因为 l 递增, 所以后面的都能够匹配.

维护信息我用了multimap...P党 呵呵.

 1 #include<cstdlib>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<map>
 5 #include<iostream>
 6 using namespace std;
 7 const int maxn = (int)1.5e5;
 8 struct S{
 9     int l,r,tp,id;
10 }seg[maxn * 2];
11 int n,m,i,j,tot;
12 int remain[maxn],finish[maxn * 2],belong[maxn];
13 multimap<int,int>M;
14 multimap<int,int>::iterator it;
15 int cmp(S a, S b){
16     if(a.l != b.l) return a.l < b.l;
17     if(a.tp != b.tp) return a.tp < b.tp;
18     return a.r < b.r;
19 }
20 int main()
21 {
22     freopen("E.in","r",stdin);
23     freopen("E.out","w",stdout);
24     ios::sync_with_stdio(false);
25     cin >> n;
26     for(i = 1; i <= n; ++i){
27         tot++;
28         cin >> seg[tot].l >> seg[tot].r;
29         seg[tot].tp = 2; seg[tot].id = i;
30     }
31     cin >> m;
32     for(i = 1; i <= m; ++i){
33         tot++;
34         cin >> seg[tot].l >> seg[tot].r >> remain[i];
35         seg[tot].tp = 1; seg[tot].id = i;
36     }
37     sort(seg+1,seg+tot+1,cmp);
38     for(i = 1; i <= tot; ++i){
39         if(finish[i]) continue;
40         if(seg[i].tp == 1){
41             if(remain[seg[i].id]) M.insert(make_pair(seg[i].r,seg[i].id));
42         }
43         else{
44             if((it = M.lower_bound(seg[i].r)) != M.end()){
45                 belong[seg[i].id] = it->second, remain[it->second]--;
46                 if(remain[it->second] == 0) M.erase(it);
47             }
48             else cout << "NO\n", exit(0);
49         }
50     }
51     cout << "YES\n";
52     for(int i = 1; i <= n; ++i) cout << belong[i] << " ";
53     return 0;
54 }

时间: 2024-08-10 15:07:55

CF 496E的相关文章

CF 496E Distributing Parts

通过这题我才知道lower_bound(set),和set::lower_bound完全他妈不一样..前者O(n)后者O(logn),去他妈的.... 思路: 另要被覆盖的线段为a[i],覆盖它的先端为b[i] 对要被覆盖的线段的左端点及a[i].lef进行离散化,然后从小到大扫描过去,如果b[i].lef<=扫描线的值就把<b[i].rig,i>加入set,如果b[i].rig<扫描线的值就从set里面删除<b[i].rig,i>,然后就处理询问了,从set里面找到离

微信 {&quot;errcode&quot;:40029,&quot;errmsg&quot;:&quot;invalid code, hints: [ req_id: Cf.y.a0389s108 ]&quot;}

{"errcode":40029,"errmsg":"invalid code, hints: [ req_id: Cf.y.a0389s108 ]"} 问题:微信网页授权后,获取到 openid 了,一刷新又没了 微信网页授权获取到的 code 只能使用一次(5分钟内有效),使用一次后,马上失效. 页面授权跳转成功,根据 code 也换取到 openid 了. 此时刷新页面,并不会再次进行授权,而是直接刷新了一下上一次授权跳转后的链接,带的还是

CF with friends and user&#39;s influence considered on NYC data(updated Aug,11st)

Here is the code link: https://github.com/FassyGit/LightFM_liu/blob/master/U_F1.py I use NYC data as other experimens. The split of the training data was seperated by the timeline, and I have normalised the interaction matrix by replacing the checkin

CF 750

今天CF打的块残废了     就是一废物 A 在24点之前到 直接模拟即可 #include<stdio.h> #include<algorithm> #include<cstring> #include<string> #include<cmath> using namespace std; #define LL long long #define MAXN 1010 #define inf 1000000000.0 int main() {

CF #394 (2) 5/6

Codeforces Round #394 (Div. 2) 总结:有毒的一场比赛.做了三题,结果A被叉,B.C挂综测,还hack失败一发,第一次在CF体会到了-50分的感觉..不知道是不是人品好,比赛时room炸了,然后,unrated.. A  水题,判一下0 0,然后abs(a-b)<=1 B  水题,组个间距比较一下,但一个数的时候要判一下 C  直接暴力上的题 D  也是xjb暴力 题意:给出n,l,r, a[], p[],另有两个数组b[], c[],ci=bi-ai.l<=ai,

一场CF的台前幕后(上)——转

前奏 大约4月份的时候,业界毒瘤pyx噔噔噔跑过来说:“酷爱!我YY了一道题!准备当CF的C” 我当时就被吓傻了."Yet another Chinese round?" “区间取模,区间求和” 感觉这题还不错?不过pyx嫌水了…… 好办!当时我刚刚出完动态仙人掌不久,于是一拍脑袋说:把这个问题出到仙人掌上去! 当然被pyx鄙视了…… 后来一直就没啥动静,直到5月底的CTSC. 试机的时候pyx给我看了套他出的神题……里面有一道题……我不小心读成了下面这个样子: “给定n个m维的模2意

[2016-03-22][CF][69A][Young Physicist]

时间:2016-03-22 19:41:34 星期二 题目编号:[2016-03-22][CF][69A][Young Physicist] 题目大意:判断向量和是否为0 分析:对应坐标相加 遇到的问题:不能用x+y+z来判断是否都为0,除非输入都是正数 #include <cstdio> using namespace std; int main(){ int a,b,c,x,y,z,n; x = y = z = 0; scanf("%d",&n); for(in

ARC下OC对象和CF对象之间的桥接(bridge)

在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环境下编译器不会自动管理CF对象的内存,所以当我们创建了一个CF对象以后就需要我们使用CFRelease将其手动释放,那么CF和OC相互转化的时候该如何管理内存呢?答案就是我们在需要时可以使用__bridge,__bridge_transfer,__bridge_retained,具体介绍和用法如下

【CF 520D】Cubes

[CF 520D]Cubes 怎么说呢--英语阅读题+超级大模拟-- 最重要的是知道怎么出来的数据...题意好懂 xy坐标内给出几个单位正方形 以正方形左下点坐标给出 y=0为地面 正方形下面或者左右下方至少存在一个正方形他才能稳定.. 正方形按0~m-1标号 每次只能取出不影响整体结构的正方形 甲乙玩一个游戏 交替取正方形 每取下一个按从左到右的顺序排好 得到一个大数 重点来了! 取出的数是m进制 转换为十进制是最终结果 甲希望结果最大 乙希望结果最小 问结果为多少 甲先取 题意明白了模拟就行