洛谷P1198 JSOI2008最大数
来源:互联网 发布:怎么加入湖南网络作协 编辑:程序博客网 时间:2024/06/16 02:58
线段树的一道好(裸)题啊,正好好久都没有写线段树了,练一下手
因为至多有M次操作所以无所谓多少个直接建个1~M的树好了
剩下乱搞一遍AC
#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int MAXN=1e6;struct sgt_tree{ int l,r,maxn; sgt_tree(){ maxn=-1e9; }}a[MAXN];int m,d,t=0,sum=0,In;char A;void build(int o,int l,int r){ a[o].l=l,a[o].r=r; if(l==r) return; build(o*2,l,(l+r)>>1); build(o*2+1,((l+r)>>1)+1,r);}int query(int o,int l,int r){ int mid=(a[o].l+a[o].r)>>1; if(a[o].l==l&&a[o].r==r) return a[o].maxn; if(l>mid) return query(o*2+1,l,r); else if(r<=mid) return query(o*2,l,r); else return max(query(o*2,l,mid),query(o*2+1,mid+1,r));}void add(int o,int p,int x){ a[o].maxn=max(a[o].maxn,x); if(a[o].l==a[o].r) return; if(p>(a[o].l+a[o].r)/2) add(o*2+1,p,x); else add(o*2,p,x);}int main(){ ios::sync_with_stdio(false); cin>>m>>d; build(1,1,m); for(int i=1;i<=m;i++){ cin>>A; if(A=='Q'){ cin>>In; t=query(1,sum-In+1,sum); printf("%d\n",t); } if(A=='A'){ cin>>In; add(1,++sum,(In+t)%d); } } return 0;}
阅读全文
4 0
- 洛谷 P1198 [JSOI2008]最大数
- [JSOI2008]最大数 洛谷p1198
- 洛谷P1198 JSOI2008最大数
- 洛谷P1198 [JSOI2008]最大数
- 洛谷 P1198 [JSOI2008]最大数
- P1198 [JSOI2008]最大数
- 洛谷 P1198 BZOJ 1012 [JSOI2008] 最大数
- 洛谷P1198 [JSOI2008]最大数(线段树)
- 洛谷 P1198 最大数
- 洛谷p1198最大数
- 洛谷 [P1198] 最大数
- [P1198]最大数
- 洛谷:JSOI2008 最大数
- 【JSOI2008】最大数
- [JSOI2008]最大数maxnumber
- jsoi2008最大数bzoj1012
- [JSOI2008]最大数
- [JSOI2008]最大数maxnumber
- WebLogic中的一些基本概念
- androidstudio--gsonformat--超爽的数据解析方式
- unity 5.x游戏开发指南——第一二三章
- POJ 2068 Nim <博弈dp>
- 使用Lock和Condition实现哲学家算法问题
- 洛谷P1198 JSOI2008最大数
- XPath学习笔记
- 内存中整型,浮点型的存储
- libcrypto.so.1.0.0: cannot open shared object file: No such file or directory解决方案
- effective javascript 第二章
- QQ空间经典文章分享
- Codeforces Round #413 (Div. 2)
- 【FirstKotlinApp】使用Kotllin封装Adapter时ViewHolder的一点技巧
- slice、splice和split的区别