HDU-2795-Billboard-线段树单点更新
2015-07-30 10:23
519 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795
好吧,写了这么多单点更新的题目,这样的就很简单了,不过我第一次用这样的风格写代码;向这种简短风格靠齐;
不过题目给的数据感觉还挺坑的,还好我机智的看了Discuss。。。。哈哈,仰天长笑。。。。
好吧,写了这么多单点更新的题目,这样的就很简单了,不过我第一次用这样的风格写代码;向这种简短风格靠齐;
不过题目给的数据感觉还挺坑的,还好我机智的看了Discuss。。。。哈哈,仰天长笑。。。。
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<queue> #include<map> #include<cmath> #include<stack> #include<set> #include<vector> #include<algorithm> #define LL long long #define inf 1<<30 #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 using namespace std; const int N=250005; int Max[N<<2]; // 用来存各个节点的最大长度; int h,w,n; void PushUp(int rt) { Max[rt]=max(Max[rt<<1],Max[rt<<1|1]); } void build(int l,int r,int rt) { Max[rt]=w; if(l==r) return; int mid=(l+r)>>1; build(lson); build(rson); } int query(int x,int l,int r,int rt) { if(l==r){ Max[rt]-=x; return l; } int mid=(l+r)>>1; int ans=0; if(Max[rt<<1]>=x) ans=query(x,lson); else ans=query(x,rson); PushUp(rt); return ans; } int main() { while(~scanf("%d%d%d",&h,&w,&n)){ if(h>n) h=n; // 这一条语句绝对不能少,虽然告诉你有10^9行,但是,我只有n张海报,所以最多有n行就够了,没有意思到这一点的话肯定会RE的; build(1,h,1); for(int i=0;i<n;i++){ int x; scanf("%d",&x); if(Max[1]<x) printf("-1\n"); else printf("%d\n",query(x,1,h,1)); } } return 0; }
相关文章推荐
- FreeRTOS 学习笔记 4 —— API 使用指南
- Ruby学习总结
- MySQL 4.1/5.0/5.1/5.5/5.6各版本的主要区别
- hdu-5313 Bipartite Graph
- Windows 10 上安装 3D Studio Max 2016 报错的解决办法
- OAuth2.0 SSO授权
- Window 开机连接ocsp.globalsign.com
- GIT常用命令
- 枚举--熄灯问题
- iOS的内存管理
- Mac OS X 下编译安装 PHP
- 编译.NET项目的时候报错错误“ResGen.exe”已退出,代码为 -1073741701
- getParameter 与 getAttribute的区别
- 扫描二维码自动识别手机系统(Android/IOS)
- Android Studio使用过程中遇到的错误
- SQL - 外键约束
- Android Studio使用过程中遇到的错误
- 编译.NET项目的时候报错错误“ResGen.exe”已退出,代码为 -1073741701
- Zznu 1913: yifan and matrix (多路归并)
- 产品汪要如何修炼——开发技能篇