POJ 3264(STRMQ)
来源:互联网 发布:恶搞剪头发软件app 编辑:程序博客网 时间:2024/05/29 15:57
for j:=1 to ln(n)/ln(2)
for i:=1 to n-(1 shl j)+1 do
f[i,j]:=min(f[i,j-1],f[i+(1 shl (j-1),j-1];
f[l,r]:=min(f[l,j],f[r-(1 shl j)+1,j]; j=ln(r-l+1)/ln(2);
ln(n)/ln(2)=log(2,n);
Program lineup;const maxn=50000; maxq=200000; maxh=1000000;var n,q,i,j,l,r,k:longint; a:array[1..maxh] of longint; f,h:array[1..maxh,0..16] of longint;//f mintall h hightallfunction min(a,b:longint):longint;begin if a<b then exit(a) else exit(b);end;function max(a,b:longint):longint;begin if a>b then exit(a) else exit(b);end;begin read(n,q); for i:=1 to n do begin read(a[i]); f[i,0]:=a[i]; h[i,0]:=a[i]; end; for j:=1 to trunc(ln(n)/ln(2)) do //f[i,j]:=min(f[i,j-1],f[i+2^(j-1),j-1] i<=n-2^j for i:=1 to n-(1 shl j)+1 do begin f[i,j]:=min(f[i,j-1],f[i+1 shl (j-1),j-1]); h[i,j]:=max(h[i,j-1],h[i+1 shl (j-1),j-1]); end; for i:=1 to q do begin read(l,r); j:=(r-l+1); j:=trunc(ln(j)/ln(2)); writeln(max(h[l,j],h[r-1 shl j +1,j])-min(f[l,j],f[r-1 shl j +1,j])); end;end.
- POJ 3264(STRMQ)
- poj 3264
- POJ 3264
- POJ 3264
- poj 3264
- POJ 3264
- poj 3264
- poj 3264
- poj 3264
- poj 3264
- POJ 3264
- poj 3264
- poj-3264
- poj 3264
- POJ-3264
- poj-3264
- POJ 3264
- POJ 3264
- Css之【字体系列】综合技巧总结(持续更新中...)
- 重装系统outlook 数据文件转移方案
- 9_9_4在类库项目Vehicles中编写代码,执行本章前面讨论的对象系列Vehicle,
- 9_9_5创建一个控制台应用程序项目Traffic,它引用Vehicles.dll
- 征服高级CSS选择器
- POJ 3264(STRMQ)
- 我的操作系统开发学习之路
- 一个数组的值先从小到大递增后从大到小递减,找出最大的值
- 代码大全精粹(三)
- 房间安排
- 操作系统开发 - BIOS常识
- 有关securitycookie在栈保护上的研究
- 大学专业学习的期望与目标
- 大学规划