poj3264
来源:互联网 发布:aucs6是什么软件 编辑:程序博客网 时间:2024/05/21 19:27
#include <iostream>#include<cstdio>#include<algorithm>using namespace std;int n,q,a[50005];struct node{ int ma,mi;}cow[500005];node inf;node inital(int l,int r,int k){ if(r-l==1) { cow[k].mi=cow[k].ma=a[l]; return cow[k]; } node c1=inital(l,(l+r)/2,k*2+1); node c2=inital((l+r)/2,r,k*2+2); cow[k].mi=min(c1.mi,c2.mi); cow[k].ma=max(c1.ma,c2.ma); return cow[k];}node query(int a,int b,int l,int r,int k){ if(a<=l&&r<=b) return cow[k]; if(r<=a||l>=b) return inf; node c1=query(a,b,l,(l+r)/2,k*2+1); node c2=query(a,b,(l+r)/2,r,k*2+2); node c; c.mi=min(c1.mi,c2.mi); c.ma=max(c1.ma,c2.ma); return c;}int main(){ inf.ma=0;inf.mi=1000000; while(cin>>n>>q) { for(int i=0;i<n;i++) scanf("%d",&a[i]); inital(0,n,0); for(int i=0;i<q;i++) { int r,l; scanf("%d%d",&l,&r); l--; node c=query( l, r,0,n,0); printf("%d\n",c.ma-c.mi); } } return 0;}
0 0
- poj3264
- poj3264
- poj3264
- poj3264
- POJ3264
- POJ3264
- POJ3264
- poj3264
- POJ3264
- poj3264
- poj3264
- poj3264
- poj3264
- POJ3264
- poj3264
- poj3264
- poj3264
- poj3264
- UVa 10539 - Almost Prime Numbers(筛选求素数)
- Java基础解惑...【Pnoter】
- mysql 学习之二 mysqldump
- Java笔记----4. 面向对象(基本概念)
- 12c In-Memory常用命令笔记
- poj3264
- yii中嵌入kindeditor
- 当人们谈论物理信息系统(CPS)的时候,他们到底在说什么?
- NSURLSession学习笔记(一)简介
- 事务隔离级别与乐观锁、悲观锁
- 2015-02-15 年前最后一编
- mobile开发中常用的css
- 两分钟开端你的Git之旅(适用于自个开发者)
- 算法精解十八(C语言版)