[JSOI2008]最大数maxnumber 线段树
2017-12-04 13:55
183 查看
题目
线段树模板题,打了个指针
代码
线段树模板题,打了个指针
代码
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #define ll long long using namespace std; ll m,d,cnt,t; struct node { node* ch[2];ll v; node(ll v):v(v){ch[0]=ch[1]=NULL;} void maintain() { if(ch[0] != NULL && v < ch[0]->v) v=ch[0]->v; if(ch[1] != NULL && v < ch[1]->v) v=ch[1]->v; } }; node* rt=NULL; void ins(node* &o,ll l,ll r,ll x) { if(o == NULL) o=new node(x); if(l >= r) return ; int mid=(l+r)>>1; if(cnt > mid) ins(o->ch[1],mid+1,r,x); else ins(o->ch[0],l,mid,x); o->maintain(); } ll query(node* o,ll l,ll r,ll ql,ll qr) { if(l > qr || r < ql || o == NULL) return 0; if(l >= ql && r <= qr) return o->v; int mid=(l+r)>>1; return max(query(o->ch[0],l,mid,ql,qr),query(o->ch[1],mid+1,r,ql,qr)); } ll read() { ll out=0,f=1;char c=getchar(); while(c < '0' || c > '9') {if(c == '-') f=-1; c=getchar();} while(c >= '0' && c <= '9') {out=(out<<3)+(out<<1)+c-'0'; c=getchar();} return out*f; } void solve() { m=read(),d=read(); for(int i=1;i<=m;i++) { char c=getchar(); while(c != 'A' && c != 'Q') c=getchar(); ll x=read(); if(c == 'A') ++cnt,ins(rt,1,m,(t+x)%d); if(c == 'Q') { t=query(rt,1,m,cnt-x+1,cnt); printf("%lld\n",t); } } } int main() { solve(); return 0; }
相关文章推荐
- BZOJ_1012_[JSOI2008]最大数maxnumber_暴力?(线段树)
- BZOJ 1012: [JSOI2008]最大数maxnumber【线段树单点更新求最值,单调队列,多解】
- BZOJ 1012: [JSOI2008]最大数maxnumber【线段树||单调栈】
- BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]
- BZOJ 1012 [JSOI2008]最大数maxnumber【线段树】
- bzoj 1012: [JSOI2008]最大数maxnumber 线段树
- [BZOJ 1012] JSOI 2008 最大数maxnumber · 线段树
- [BZOJ 1012][JSOI2008]最大数maxnumber:线段树|单调栈
- 【听说是线段树】bzoj1012 [JSOI2008]最大数maxnumber
- BZOJ 1012: [JSOI2008]最大数maxnumber 单调队列/线段树
- BZOJ 1012 JSOI2008 最大数maxnumber 单调栈+二分 / 线段树
- bzoj1012 [JSOI2008] 最大数maxnumber 线段树
- BZOJ 1012[jsoi2008] 最大数maxnumber 线段树(或者是单调队列+二分)
- BZOJ-1012[JSOI2008]最大数maxnumber 线段树区间最值
- [BZOJ1012][JSOI2008][线段树]最大数maxnumber
- BZOJ-1012[JSOI2008]最大数maxnumber 线段树区间最值
- 1012: [JSOI2008]最大数maxnumber 线段树区间统计
- BZOJ 1012: [JSOI2008]最大数maxnumber 线段树
- [BZOJ] 1012 - [JSOI2008] - 最大数maxnumber - 线段树 - 单点更新 - 区间查询最大
- 【线段树】【JSOI 2008】【bzoj 1012】最大数maxnumber