2014多校10(1003)hdu4973(简单线段树区间操作)

A simple simulation problem.

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 679    Accepted Submission(s): 269


Problem Description
There are n types of cells in the lab, numbered from 1 to n. These cells are put in a queue, the i-th cell belongs to type i. Each time I can use mitogen to double the cells in the interval [l, r]. For instance, the original queue is {1 2 3 3 4 5}, after using a mitogen in the interval [2, 5] the queue will be {1 2 2 3 3 3 3 4 4 5}. After some operations this queue could become very long, and I can’t figure out maximum count of cells of same type. Could you help me?
 

Input
The first line contains a single integer t (1 <= t <= 20), the number of test cases.

For each case, the first line contains 2 integers (1 <= n,m<= 50000) indicating the number of cell types and the number of operations.

For the following m lines, each line represents an operation. There are only two kinds of operations: Q and D. And the format is:

“Q l r”, query the maximum number of cells of same type in the interval [l, r];
“D l r”, double the cells in the interval [l, r];

(0 <= r – l <= 10^8, 1 <= l, r <= the number of all the cells)
 

Output
For each case, output the case number as shown. Then for each query "Q l r", print the maximum number of cells of same type in the interval [l, r].

Take the sample output for more details.
 

Sample Input
   
   
1 5 5 D 5 5 Q 5 6 D 2 3 D 1 2 Q 1 7
 

Sample Output
   
   
Case #1: 2 3

题意:两种操作,D L R 将L到R区间的数的数量加倍,Q L R 查询区间内数量最多的数的个数

思路:由于初始给出的是1到n按顺序,那么无论怎么加倍,相同的数一定排在一起,这样可以用线段树维护整个序列,值为每个数的个数

            D L R 先将L点和R点的数的数量增加一定数量(不一定是加倍),然后将L+1到R-1的数的数量加倍
 
            Q L R 在L点,R点和[L+1,R-1]的选一个最大值

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         using namespace std; #define lson l,m,o<<1 #define rson m+1,r,o<<1|1 #define maxn 50010 typedef __int64 ll; ll sum[maxn<<2]; ll f[maxn<<2]; ll mx[maxn<<2]; ll maxi(ll x,ll y) { return x>y ? x:y ; } void pushup(int o) { sum[o]=sum[o<<1]+sum[o<<1|1]; mx[o]=maxi( mx[o<<1] , mx[o<<1|1] ); } void pushdown(int o) { if(f[o]>1) { f[o<<1]*=f[o]; f[o<<1|1]*=f[o]; sum[o<<1]*=f[o]; sum[o<<1|1]*=f[o]; mx[o<<1]*=f[o]; mx[o<<1|1]*=f[o]; f[o]=1; } } void build(int l,int r,int o) { f[o]=1; if(l==r){ sum[o]=1; mx[o]=1; return; } int m=l+r>>1; build(lson); build(rson); pushup(o); } ll tea[3][5]; int d; void query(int l,int r,int o,ll k) { if(l==r){ tea[d][0]=l; tea[d][1]=k; tea[d++][2]=sum[o]; return; } pushdown(o); int m=l+r>>1; if(sum[o<<1]>=k)query(lson,k); else query(rson,k-sum[o<<1]); pushup(o); } ll querysgment(int l,int r,int o,ll L,ll R) { if(L<=l&&r<=R)return mx[o]; pushdown(o); int m=l+r>>1; ll xa=0; if(L<=m)xa=maxi(xa,querysgment(lson,L,R)); if(m 
        
          >1; pushdown(o); if(p<=m)updatevex(lson,p,v); else updatevex(rson,p,v); pushup(o); } void updatesgument(int l,int r,int o,ll L,ll R) { if(L<=l&&r<=R){ mx[o]+=mx[o]; sum[o]+=sum[o]; f[o]+=f[o]; return; } pushdown(o); int m=l+r>>1; if(L<=m)updatesgument(lson,L,R); if(m 
         
           1)updatesgument(1,n,1,tea[0][0]+1,tea[1][0]-1); } } else { if(tea[0][0]==tea[1][0])printf("%I64d\n",tea[1][1]-tea[0][1]+1); else { ll ans=maxi(tea[0][2]-tea[0][1]+1 , tea[1][1]); if(tea[1][0]-tea[0][0]<=1)printf("%I64d\n", ans ); else { ans=maxi(ans, querysgment(1,n,1,tea[0][0]+1,tea[1][0]-1)); printf("%I64d\n", ans ); } } } } } return 0; } 
          
         
       
      
      
     
     
    
    
   
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值