【jzoj5329】【NOIP2017提高A组模拟8.22】【时间机器】【数据结构】【扫描线】
来源:互联网 发布:威海市网络推广专员 编辑:程序博客网 时间:2024/05/17 22:44
description
solution
把机器和电阻按l排序,l相等时电阻排前面,扫描线从左往右扫,遇到电阻把右端点放入set,遇到机器lowerbound找到最小的r比机器的r大匹配即可。
code
#include<set>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#define LL long long#define fo(i,j,k) for(int i=j;i<=k;i++)#define fd(i,j,k) for(int i=j;i>=k;i--)#define fr(i,j) for(int i=begin[j];i;i=next[i])using namespace std;int const mn=1e5+9,inf=1e9+7;int t,n,m;struct rec{ int l,r,s,op;};rec a[mn];struct re2{ int r,s; friend bool operator<(re2 x,re2 y){ return (x.r<y.r)||((x.r==y.r)&&(x.s<y.s)); } re2(int R,int S){ r=R;s=S; }};multiset<re2>s;bool cmp(rec x,rec y){ return (x.l<y.l)||((x.l==y.l)&&(x.op>y.op));}int read(){ char ch=getchar(); while((ch<'0')||(ch>'9'))ch=getchar(); int v=0; while((ch>='0')&&(ch<='9'))v=v*10+ch-'0',ch=getchar(); return v;}int main(){ freopen("machine.in","r",stdin); freopen("machine.out","w",stdout); scanf("%d",&t); fo(cas,1,t){ scanf("%d%d",&n,&m); int tmp=0; fo(i,1,n){ tmp++; a[tmp].l=read(); a[tmp].r=read(); a[tmp].s=read(); a[tmp].op=-1; } fo(i,1,m){ tmp++; a[tmp].l=read(); a[tmp].r=read(); a[tmp].s=read(); a[tmp].op=1; } sort(a+1,a+tmp+1,cmp); int ok=1; s.clear(); fo(i,1,tmp)if(a[i].op==1) s.insert(re2(a[i].r,a[i].s)); else{ while((a[i].s)&&(s.lower_bound(re2(a[i].r,0))!=s.end())){ re2 tm2=*s.lower_bound(re2(a[i].r,0)); s.erase(s.lower_bound(re2(a[i].r,0))); int tm3=min(a[i].s,tm2.s); a[i].s-=tm3; if(tm3!=tm2.s)s.insert(re2(tm2.r,tm2.s-tm3)); } if(a[i].s){ ok=0; break; } } if(ok)printf("Yes\n"); else printf("No\n"); } return 0;}
阅读全文
0 0
- 【jzoj5329】【NOIP2017提高A组模拟8.22】【时间机器】【数据结构】【扫描线】
- 【JZOJ5329】【NOIP2017提高A组模拟8.22】时间机器
- 5329. 【NOIP2017提高A组模拟8.22】时间机器 map
- JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器
- 【NOIP2017提高A组模拟8.22】时间机器
- 【NOIP2017提高A组模拟8.22】密码
- 【jzoj5334】【NOIP2017提高A组模拟8.24】【空】【扫描线】【set】
- 【jzoj5328】【NOIP2017提高A组模拟8.22】【世界线】【bitset】
- JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线
- 【NOIP2017提高A组模拟8.22】世界线
- 世界线 【NOIP2017提高A组模拟8.22】
- 【JZOJ5328】【NOIP2017提高A组模拟8.22】世界线
- 【jzoj5289】【NOIP2017提高组A组模拟8.17】【偷笑】【数据结构】
- jzoj5330 【NOIP2017提高A组模拟8.22】密码
- A【NOIP2017提高组模拟12.18】
- 【JZOJ4928】【NOIP2017提高组模拟12.18】A
- 【NOIP2017提高组模拟12.18】A
- 【JZOJ4928】【NOIP2017提高组模拟12.18】A
- 好用的工具
- Alpha选股:资本资产定价模型(CAPM)
- poj 3695 Rectangles(容斥原理)
- 题目1040:Prime Number
- 源代码安全管理
- 【jzoj5329】【NOIP2017提高A组模拟8.22】【时间机器】【数据结构】【扫描线】
- SAP/ABAP: Smartforms, SSF_OPEN, SSF_CLOSE
- POJ 2417 Discrete Logging(离散对数 BSGS)
- 记一次WebService失败重构
- java.lang.NoClassDefFoundError:com/fasterxml/jackson/databind/ObjectMapper
- Android 8.0 正式发布,Google 带来了哪些新功能?
- 使用Visio对mysql数据库反工程
- 菜鸟 理解Unity 优化
- 写在前面。