「CF497C」Distributing Parts
题解
按照右端点排序后贪心,每个人优先选左端点最小的歌
用平衡树维护即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<set> #include<ctime> #include<vector> #include<queue> #include<algorithm> #include<map> #define inf 1000000000 #define pa pair<int,int> #define ll long long using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m; int num[100005],ans[100005]; struct data{ int l,r,K,id; }a[100005],b[100005]; bool operator<(data a,data b) { return a.r<b.r; } set<pa> q; int main() { n=read(); for(int i=1;i<=n;i++) a[i].l=read(),a[i].r=read(),a[i].id=i; sort(a+1,a+n+1); m=read(); for(int i=1;i<=m;i++) b[i].l=read(),b[i].r=read(),b[i].K=read(),b[i].id=i; sort(b+1,b+m+1); int now=1; for(int i=1;i<=m;i++) { while(b[i].r>=a[now].r&&now<=n) { q.insert(make_pair(a[now].l,now)); now++; } while(b[i].K--) { set<pa>::iterator p=q.lower_bound(make_pair(b[i].l,0)); if(p==q.end())break; ans[a[p->second].id]=b[i].id; q.erase(p); } } for(int i=1;i<=n;i++) if(!ans[i]) { puts("NO"); return 0; } puts("YES"); for(int i=1;i<=n;i++) printf("%d ",ans[i]); return 0; } |
Subscribe