题目描述
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!
输入
The first line contains a single integer n — the number of parts in the play ( 1 ≤ n ≤ 105 1 ≤ n ≤ 10 5 ).
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 1 ≤ a j ≤ b j ≤ 10 9 ).
The next line contains a single integer m — the number of actors ( 1 ≤ m ≤ 105 1 ≤ m ≤ 10 5 ).
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 1 ≤ c i ≤ d i ≤ 10 9 , 1 ≤ k i ≤ 10 9 ).
输出
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).
样例
input
3
1 3
2 4
3 5
2
1 4 2
2 5 1
output
YES
1 1 2
input
3
1 3
2 4
3 5
2
1 3 2
2 5 1
output
NO
题意
现在有场演唱会 每个演唱家演唱的节奏时间是不同的
先给出
n
n
个需要演奏曲子的区间
在给m个演唱家 可以演唱的区间
[ci,di]
[
c
i
,
d
i
]
区间后面跟着
k
k
<script type="math/tex" id="MathJax-Element-8">k</script>个演唱家可以演唱的次数
让构造一个方案使演唱会进行 不能输出NO
明显我们可以先对两个区间按右端点升序重排下,然后把演奏曲子右端点小于演唱家的扔进set里面, 然后就是用set维护
AC代码
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define CLR(a,b) memset(a,(b),sizeof(a))
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5+11;
int n, m;
struct node
{
int l, r, k;
int id, ak;
bool operator <(const node &cc)const {
if(r == cc.r) return l < cc.l;
return r < cc.r;
}
}a[MAXN], b[MAXN];
struct node_1
{
int l, r;
int id;
bool operator <(const node_1 &cc)const {
if(l == cc.l) {
if(r == cc.r)
return id < cc.id;
return r < cc.r;
}
return l < cc.l;
}
};
set<node_1> st;
bool cmp(node x, node y)
{
return x.id < y.id;
}
void sert(int x, int y,int z)
{
node_1 xy;
xy.l = x;
xy.r = y;
xy.id = z;
st.insert(xy);
}
int main()
{
ios::sync_with_stdio(false),cin.tie(0);
cin >> n;
int kk = 1;
for(int i = 1; i <= n; i++) {
cin >> a[i].l >> a[i].r;
a[i].id = i;
}
cin >> m;
for(int i = 1; i <= m; i++) {
cin >> b[i].l >> b[i].r >> b[i].k;
b[i].id = i;
}
sort(b+1, b+1+m); sort(a+1, a+1+n);
for(int i=1,j=1; i <= m; i++) {
while(j<=n && a[j].r<=b[i].r) {
sert(a[j].l,a[j].r,j);
j++;
}
while(b[i].k--) {
set<node_1>::iterator it = st.lower_bound((node_1){b[i].l,0,0});
if(it == st.end()) break;
a[it->id].ak = b[i].id;
st.erase(it);
kk++;
}
}
if(!st.empty() || kk<=n) {
cout << "NO\n"; return 0;
}
cout << "YES\n";
sort(a+1, a+1+n, cmp);
for(int i = 1; i <= n; i++) {
if(i != n)
cout << a[i].ak << ' ';
else
cout << a[i].ak << endl;
}
return 0;
}