BZOJ1012 [JSOI2008]最大数maxnumber
暂时不知道别的,直接上了线段树
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 #define lson l,m,rt<<1 6 #define rson m+1,r,rt<<1|1 7 const int maxn = 200005; 8 int sum[maxn<<2]; 9 void pushup(int rt){ 10 sum[rt] = max(sum[rt<<1],sum[rt<<1|1]); 11 } 12 void update(int pos,int val,int l,int r,int rt){ 13 if(l==r){ 14 sum[rt] = val; 15 return ; 16 } 17 int m = (l+r)>>1; 18 if(pos<=m)update(pos,val,lson); 19 else update(pos,val,rson); 20 pushup(rt); 21 } 22 int query(int L,int R,int l,int r,int rt){ 23 if(L<=l&&r<=R)return sum[rt]; 24 int m = (l+r)>>1,ans = -1; 25 if(L<=m)ans = max(ans,query(L,R,lson)); 26 if(m<R)ans = max(ans,query(L,R,rson)); 27 return ans; 28 } 29 int main() 30 { 31 int q,mod; 32 scanf("%d%d",&q,&mod); 33 memset(sum,-1,sizeof(sum)); 34 int t =0,a,pos = 1;char s[2]; 35 while(q--){ 36 scanf("%s%d",s,&a); 37 if(s[0]=='A')update(pos++,(a+t)%mod,1,maxn-1,1); 38 else { 39 t = query(pos-a,maxn-1,1,maxn-1,1); 40 printf("%d\n",t); 41 } 42 } 43 return 0; 44 }
弱者究竟为何而战?!