bzoj 1012 线段树
来源:互联网 发布:sublime text 3编译js 编辑:程序博客网 时间:2024/05/01 15:36
题意:初始为空,两种操作::(1) Q L :查询当前数列中末尾L个数中的最大的数,并输出这个数的值。保证L不超过当前数列的长度。(2)A n :将n加上最近一次查询操作的答案(如果还未执行过查询操作,则t=0),对常数D取模,将所得答案插入到数列的末尾。
一眼过去,直觉告诉我是线段树...
type rec=record l,r,max:longint;end;var n,m,tt,mo,x :longint; ch :char; i :longint; t :array[0..800010] of rec;function max(a,b:longint):longint;begin if a<b then exit(b) else exit(a);end;procedure build(x,l,r:longint);var mid:longint;begin t[x].l:=l; t[x].r:=r; if l=r then exit; mid:=(l+r)>>1; build(2*x,l,mid); build(2*x+1,mid+1,r);end;procedure insert(x,y,z:longint);var mid:longint;begin if t[x].l=t[x].r then begin t[x].max:=z;exit; end; mid:=(t[x].l+t[x].r)>>1; if y<=mid then insert(2*x,y,z) else insert(2*x+1,y,z); t[x].max:=max(t[2*x].max,t[2*x+1].max);end;function get_max(x,l,r:longint):longint;var mid:longint;begin if (t[x].l=l) and (t[x].r=r) then exit(t[x].max); mid:=(t[x].l+t[x].r)>>1; if r<=mid then exit(get_max(2*x,l,r)) else if l>mid then exit(get_max(2*x+1,l,r)) else exit(max(get_max(2*x,l,mid),get_max(2*x+1,mid+1,r)));end;begin readln(m,mo); tt:=0; n:=0; build(1,1,m); for i:=1 to m do begin read(ch);readln(x); if ch='A' then begin inc(n); x:=(x+tt) mod mo; insert(1,n,x); end else begin tt:=get_max(1,n-x+1,n); writeln(tt); end; end;end.——by Eirlys
0 0
- BZOJ 1012 线段树
- bzoj 1012 线段树
- BZOJ 1012 线段树||单调队列
- bzoj 1012 简单的线段树
- bzoj 1012 最大数 线段树 || 分块
- BZOJ 1012 线段树或单调栈
- BZOJ 1012 线段树 解题报告
- bzoj 1012 最大数 maxnumber 线段树
- bzoj 线段树专刊
- bzoj 1798 线段树
- bzoj 4388 线段树
- BZOJ 1798 线段树
- BZOJ 1112 线段树
- BZOJ 3339 线段树
- bzoj 2957 线段树
- bzoj 2752 线段树
- bzoj 3519 线段树
- bzoj 1798 线段树
- react——组件API
- Android -- RecyclerView实现顶部吸附效果
- 微信小程序-修改数据后页面不渲染
- Ackerman函数
- Android Studio 上传aar(Library)到JCenter
- bzoj 1012 线段树
- 宽字节
- 变量的定义和变量使用的原因
- Xshell无法连接虚拟机解决办法
- HTML5无插件多媒体Media——音频audio与视频video
- Android中dp,sp以及px之间的关系
- 制定个学习计划
- JavaScript图片轮播代码
- Oculus Rift CV1 驱动安装教程(内含Oculus官方Demo)