bzoj 1012 最大数 线段树 || 分块
来源:互联网 发布:nlp分词算法 编辑:程序博客网 时间:2024/05/22 00:54
线段树提前开20w个点建树就可以直接修改。
#include<iostream>#include<cstdio>#define LL long longusing namespace std;struct xds{ int l,r; LL ma;}tree[800005];void build(int dq,int l,int r){ tree[dq].l=l; tree[dq].r=r; if(l==r) return ; int mid=(l+r)>>1; build(dq<<1,l,mid); build(dq<<1|1,mid+1,r);}LL ask(int dq,int l,int r){ if(tree[dq].l>=l&&tree[dq].r<=r) return tree[dq].ma; LL ans=0; int mid=(tree[dq].l+tree[dq].r)>>1; if(mid>=l) ans=max(ans,ask(dq<<1,l,r)); if(mid<r) ans=max(ans,ask(dq<<1|1,l,r)); return ans; }void up(int dq){ tree[dq].ma=max(tree[dq<<1].ma,tree[dq<<1|1].ma);}void change(int dq,int c,LL v){ if(tree[dq].l==tree[dq].r) { tree[dq].ma=v; return ; } int mid=(tree[dq].r+tree[dq].l)>>1; if(mid>=c) change(dq<<1,c,v); else change(dq<<1|1,c,v); up(dq);}int main(){ int m;LL d,n,t=0;int tot=0; char a;int x; scanf("%d%lld",&m,&d); build(1,1,m); for(int i=1;i<=m;i++) { a=getchar(); while(a!='A'&&a!='Q') a=getchar(); if(a=='Q') { scanf("%d",&x); t=ask(1,tot-x+1,tot); printf("%d\n",t); } else { scanf("%lld",&n); n+=t;n%=d; tot++; change(1,tot,n); } } return 0;}
2 0
- bzoj 1012 最大数 线段树 || 分块
- bzoj 1012 最大数 maxnumber 线段树
- [BZOJ 1012] JSOI 2008 最大数maxnumber · 线段树
- bzoj 1012 最大数(线段树|单调队列|单调栈)
- 【线段树】【JSOI 2008】【bzoj 1012】最大数maxnumber
- BZOJ 题目1012: [JSOI2008]最大数maxnumber(线段树)
- bzoj 1012: [JSOI2008]最大数maxnumber(线段树)
- BZOJ 1012 最大数maxnumber 单调队列或线段树
- |BZOJ 1012|线段树|[JSOI2008]最大数maxnumber
- 【BZOJ 1012】 [JSOI2008]最大数maxnumber(线段树做法)
- BZOJ 1012: [JSOI2008]最大数maxnumber 单调队列/线段树
- BZOJ 1012: [JSOI2008]最大数maxnumber 线段树入门题
- [BZOJ 1012][JSOI2008]最大数maxnumber:线段树|单调栈
- Luogu P1198 BZOJ 1012 最大数 (线段树)
- BZOJ 1012[JSOI2008]最大数maxnumber (线段树解法)
- 【bzoj 1012】最大数maxnumber(线段树)
- BZOJ 2141 分块 线段树
- [树状数组套权值线段树 || 分块] BZOJ 2120 数颜色 & BZOJ 2453 维护队列
- MapReduce 详解一
- Java mail基础使用 (一)
- MYSQL条件查询--字段A不同值的state为0,1,9的数量统计
- C++ 面向对象程序设计上机练习一(函数重载)
- 读《包法利夫人》有感
- bzoj 1012 最大数 线段树 || 分块
- MySQL5.6 Innodb独立的undo tablespace
- ajax传递json数组,只会传递一个
- MBProgressHUD的提示很快就消失了
- App启动页--实现二
- ViewDragHelper
- OpenGL系列教程之八:OpenGL顶点缓冲区对象(VBO)
- codevs3729: [NOIP2014]飞扬的小鸟
- I/O流