poj --3264
2015-06-10 19:09
274 查看
又手贱的用cin 结果t掉;
感觉自己的代码风格太差了
http://poj.org/problem?id=3264
代码君
感觉自己的代码风格太差了
http://poj.org/problem?id=3264
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int INF = 0xffffff0; int minV = INF; int maxV = -INF; typedef struct _NODE_ { int L,R; int minV,maxV; int Mid() { return (L+R)/2; } }NODE; NODE tree[800000 + 10]; void BuildTree(int root,int L,int R) { tree[root].L = L; tree[root].R = R; tree[root].minV = INF; tree[root].maxV = -INF; if (L!=R) { BuildTree(2*root+1,L,(L+R)/2); BuildTree(2*root+2,(L+R)/2+1,R); } } void Insert(int root,int i,int v) { if (tree[root].L==tree[root].R) { tree[root].minV = tree[root].maxV = v; return ; } tree[root].minV = min(tree[root].minV,v); tree[root].maxV = max(tree[root].maxV,v); if (i<=tree[root].Mid()) { Insert(2*root+1,i,v); } else { Insert(2*root+2,i,v); } } void Query(int root,int s,int e) { if (tree[root].minV>=minV&&tree[root].maxV<=maxV) { return ; } if (tree[root].L == s&&tree[root].R == e) { minV = min(minV,tree[root].minV); maxV = max(maxV,tree[root].maxV); return ; } if (e<=tree[root].Mid()) { Query(2*root+1,s,e); } else if (s>tree[root].Mid()) { Query(2*root+2,s,e); } else { Query(2*root+1,s,tree[root].Mid()); Query(2*root+2,tree[root].Mid()+1,e); } } void work(int n ,int q) { BuildTree(0,1,n); for (int i = 1;i<=n;i++) { int h; scanf("%d",&h); Insert(0,i,h); } for (int i = 0;i<q;i++) { int s,e; scanf("%d%d",&s,&e); minV = INF; maxV = -INF; Query(0,s,e); cout << maxV-minV << endl; } } int main() { int n,q,h; int i,j,k; scanf("%d%d",&n,&q); work(n,q); return 0; }
代码君
相关文章推荐
- 360技术开发实习笔试题2-java
- JSON和JAVA的bean的相互转换
- 修改应用程序的包名
- 海盗分金问题
- HDU 4821 字符串hash
- SQLserver 连接+开窗函数+视图+事务
- Nginx和PHP-FPM的启动/重启脚本 [转发]
- 第十四周 项目一--小玩文件(3)
- WSAIoctl 函数详解
- 权重随机算法Java实现
- C#语言开发的WinForm简易计算器
- Linux iptables:规则原理和基础
- URAL1005 Stone Pile
- JS实现简单的图片轮换效果
- 非多态简单格斗游戏
- kafka文档(转)
- WinSock2编程之打造完整的SOCKET池
- 兔斯基 经典语录
- 如何抓取扬声器的声音
- css中的clear和float