[Hall定理 + 线段树] LibreOJ#6062. 「2017 山东一轮集训 Day2」Pair
来源:互联网 发布:云和大数据的关系 编辑:程序博客网 时间:2024/06/01 09:52
可以先对
对于一个
由于图的特殊性,
这样就很简单了,只要满足对于所有
枚举所有可能子段,用线段树维护
#include<cstdio>#include<algorithm>using namespace std;const int maxn=200005;int n,m,H,ans,a[maxn],b[maxn],L[maxn];struct node{ int _min,tag; node* ch[2]; node(int x=0){_min=x;tag=0;ch[0]=ch[1]=0;} void Plus(int x){ _min+=x; tag+=x; } void pushdown(){ if(tag) ch[0]->Plus(tag), ch[1]->Plus(tag), tag=0; } void maintain(){ _min=min(ch[0]->_min,ch[1]->_min); }} *root, base[maxn*2], *p_top=base;typedef node* P_node;void Updata(P_node p,int L,int R,int qL,int qR,int val){ if(R<qL||qR<L||qL>qR) return; if(qL<=L&&R<=qR){ p->Plus(val); return; } int mid=(L+R)>>1; p->pushdown(); Updata(p->ch[0],L,mid,qL,qR,val); Updata(p->ch[1],mid+1,R,qL,qR,val); p->maintain();}P_node newnode(){ *p_top=node(2e9); return p_top++; }P_node Build(int L,int R){ P_node p=newnode(); if(L==R){ p->_min=-L; return p; } int mid=(L+R)>>1; p->ch[0]=Build(L,mid); p->ch[1]=Build(mid+1,R); p->maintain(); return p;}int Find(int x){ int L=1,R=m,res=m+1; while(L<=R){ int mid=(L+R)>>1; if(x<=b[mid]) R=mid-1, res=mid; else L=mid+1; } return res;}int main(){ freopen("loj6062.in","r",stdin); freopen("loj6062.out","w",stdout); scanf("%d%d%d",&n,&m,&H); for(int i=1;i<=m;i++) scanf("%d",&b[i]); sort(b+1,b+1+m); for(int i=1;i<=n;i++) scanf("%d",&a[i]),L[i]=Find(H-a[i]); if(m>n) return puts("0"),0; root=Build(1,m); for(int i=1;i<=m;i++) Updata(root,1,m,L[i],m,1); for(int i=m;i<=n;i++,Updata(root,1,m,L[i],m,1),Updata(root,1,m,L[i-m],m,-1)) if(root->_min>=0) ans++; printf("%d\n",ans); return 0;}
阅读全文
0 0
- [Hall定理 + 线段树] LibreOJ#6062. 「2017 山东一轮集训 Day2」Pair
- loj #6062. 「2017 山东一轮集训 Day2」Pair(线段树)
- [线段树][二分图 霍尔定理]LOJ#6062 && 2017 山东一轮集训 Day2. Pair
- [霍尔定理]「2017 山东一轮集训 Day2」LOJ 6062——PAIR
- LOJ #6077. 「2017 山东一轮集训 Day7」逆序对
- LOJ #6077. 「2017 山东一轮集训 Day7」逆序对
- [倍增NTT][DP] LOJ#6059. 「2017 山东一轮集训 Day1」Sum
- [动态网络 网络流] LOJ#6068.「2017 山东一轮集训 Day4」棋盘
- [最短路 杂题] LOJ#6075. 「2017 山东一轮集训 Day6」重建
- [莫队维护DP] LOJ#6074. 「2017 山东一轮集训 Day6」子序列
- [费用流]LOJ#6079. 「2017 山东一轮集训 Day7」养猫
- [后缀自动机 DP] LOJ#6071. 「2017 山东一轮集训 Day5」字符串
- [分块 回文自动机] LOJ#6070. 「2017 山东一轮集训 Day4」基因
- [容斥 DP] LOJ#6077. 「2017 山东一轮集训 Day7」逆序对
- BZOJ 2138: stone Hall定理 线段树
- loj 6062 (hall定理+ 线段树)
- [LOJ#6060][线性基]2017 山东一轮集训 Day1. Set
- [树的同构][二分][可并堆维护哈希] LOJ#6066 || BZOJ4928 && 2017 山东一轮集训 Day3. 第二题
- [BZOJ]1227: [SDOI2009]虔诚的墓主人 树状数组
- Xshell连接不上虚拟机ubuntn的问题
- 1、Two Sum(两数之和)
- 编程思想:面向对象和面向过程
- Java排序总结
- [Hall定理 + 线段树] LibreOJ#6062. 「2017 山东一轮集训 Day2」Pair
- centos5.X yum源地址变更
- 树的重心 poj
- Servlet 过滤器
- oracle数据库sql语句01
- Linux下的两种链接命令
- 模拟光电路简介
- HDU2473 Junk-Mail Filter 解题报告【并查集+虚父节点】
- poj1912:A highway and the seven dwarfs(凸包)