楼房重建
来源:互联网 发布:淘宝体检中心进不去 编辑:程序博客网 时间:2024/06/09 16:52
楼房重建
线段树
bzoj2957
题解:
Code:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 100005;struct Node{ int l,r,mid; int ans; double maxk;}t[N*4];void build(int num,int l,int r){ Node &now=t[num]; now.l=l; now.r=r; now.mid=(l+r)>>1; now.ans=0; now.maxk=0.0; if(l!=r){ build(num*2,l,now.mid); build(num*2+1,now.mid+1,r); }}int count(int num,double limit){ Node &now=t[num]; if(now.l==now.r) return now.maxk>limit; Node &lch=t[num*2], &rch=t[num*2+1]; if(lch.maxk<=limit) return count(num*2+1,limit); else return now.ans-lch.ans+count(num*2,limit);}void change(int num,int x,double k){ Node &now=t[num]; if(now.l==now.r){ now.ans=1; now.maxk=k; } else{ if(x<=now.mid) change(num*2,x,k); else change(num*2+1,x,k); Node &lch=t[num*2], &rch=t[num*2+1]; now.maxk=max(lch.maxk,rch.maxk); now.ans=lch.ans+count(num*2+1,lch.maxk); }}void read(int &num){ num=0; char c; while(!isdigit(c=getchar())); num=c-'0'; while(isdigit(c=getchar()))num=num*10+c-'0';}int n,m;int main(){ freopen("building.in","r",stdin); read(n); read(m); build(1,1,n); int x,y; for(int i=1;i<=m;i++){ read(x); read(y); change(1,x,double(y)/x); printf("%d\n",t[1].ans); }}
阅读全文
0 0
- 楼房重建
- bzoj 2957 楼房重建
- bzoj 2957: 楼房重建
- bzoj-2957 楼房重建
- 【THUSC 2013】楼房重建
- BZOJ 2957 楼房重建
- 【BZOJ2957】楼房重建
- bzoj 2957: 楼房重建
- bzoj2957: 楼房重建
- bzoj2957 楼房重建
- BZOJ2957 楼房重建
- 2957: 楼房重建
- 【Bzoj2957】楼房重建
- BZOJ 2957: 楼房重建
- 2957: 楼房重建
- BZOJ2957 楼房重建
- BZOJ2957 楼房重建
- bzoj2957 楼房重建
- 组合数求模
- OPNET LINK : fatal error LNK1181如何解决
- Fox And Two Dots
- hdu 2642 (summerIII J) 二维树状数组
- 【GRE】做题记录和总结
- 楼房重建
- PRML:二元变量分布
- Android 图片浏览功能简单实现(画廊效果实现,支持放大缩小)
- 通过Android Studio查看SDK源码
- Python3.6笔记之腌制泡菜(pickle模块的用法)
- 《Thinking In Algorithm》06.Binary search tree(二叉查找树)
- “使用plt.savefig()保存图片时,一片空白”的解决方法
- Vray户型渲染
- (4)标签分类