标签:its erase https color code 优先 nbsp col inline
[题目链接]
https://codeforces.com/contest/496/problem/E
[算法]
按右端点排序 , 每个乐曲优先选取的左端点最大的演奏家
用std :: set维护贪心
时间复杂度 : O(NlogN)
[代码]
#include<bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int inf = 2e9; int n , m; struct info { int l , r , k , home; bool type; } a[MAXN << 1]; 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 = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == ‘-‘) f = -f; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - ‘0‘; 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 = 1; i <= n; i++) { int l , r; scanf("%d%d",&l,&r); a[i] = (info){l,r,0,i,false}; } read(m); for (int i = 1; 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 + 1,a + (n + m) + 1,cmp); for (int i = 1; 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 0; } it--; pair< int,pair<int,int> > tmp = (*it); s.erase(it); ans[a[i].home] = tmp.second.second; if (tmp.second.first > 1) s.insert(make_pair(tmp.first,make_pair(tmp.second.first - 1,tmp.second.second))); it = s.find(make_pair(a[i].l,make_pair(inf,inf))); s.erase(it); } } printf("YES\n"); for (int i = 1; i <= n; i++) printf("%d ",ans[i]); printf("\n"); return 0; }
[Codeforces 496E] Distributing Parts
标签:its erase https color code 优先 nbsp col inline
原文地址:https://www.cnblogs.com/evenbao/p/9739195.html