2014 Multi-University Training Contest 3小记

1005


char  str[1000000000] ;

int   main(){
      int n  , i , j  , no ;
      string s ;
      LL  sum  ,  a , t  ;
      char  ch  ;
      while(scanf("%d" , &n) != EOF){
           getchar() ;
           no = 0 ;
           s = "" ;
           sum = 1 ;
           for(i = 1 ; i <= n ; i++){
               gets(str) ;
               s += string(str) ;
           }
           for(i = 0  ; i < s.length() ; i++){
               if(s[i] == '{'){
                    t = 0 ;
                    for(j = i + 1 ; s[j] != '}' ; j++){
                         if(s[j] == '|')  t++ ;
                    }
                    if(t > 100000LL){
                                        no = 1 ; break ;
                    }
                    sum *= (t + 1) ;
                    if(sum > 100000LL){
                         no = 1 ;
                         break ;
                    }
                    i = j ;
               }
               else if(s[i] == '$'){
                    t = 1 ;
                    LL c = 0LL ;
                    for(j = i + 1 ; s[j] != '$' ; j++){
                         if(s[j] == ' '){
                              c++ ;
                              if(c > 100000LL){
                                        no = 1 ; break ;
                                }
                         }
                         else{
                             if(c != 0){
                                    t *= (c + 1) ;
                                    if(t > 100000LL){
                                        no = 1 ; break ;
                                    }
                                    c = 0LL ;
                             }
                         }
                    }
                    if(c != 0){
                        t *= (c + 1) ;
                        c = 0LL ;
                    }
                    if(t > 100000LL){
                            no = 1 ; break ;
                    }
                    sum *= t ;
                    if(sum > 100000LL){
                         no = 1 ;
                         break ;
                    }
                    i = j ;
               }
           }
           if(sum > 100000LL) no = 1 ;
           if(no == 1)  puts("doge") ;
           else         cout <<  sum  << endl  ;
      }
      return  0  ;
}


1007

typedef  long  long  LL ;

set<LL> st ;
set<LL> ::iterator it ;
LL  a[100] ;

void Fibonacci(){
    a[0] = a[1] = 1;
    for (int i = 2 ; i <= 80 ; i++) {
        a[i] = a[i-1] + a[i-2];
    }
    for(int i = 0 ; i <= 80 ; i++)  st.insert(a[i]) ;
}

const  int  maxn = 100008 ;

int  color[maxn<<2] ;
LL   sum[maxn<<2]  , x[maxn] ;

void  make(int l , int r , int t){
      color[t] = -1 ;
      sum[t] = 0LL ;
      if(l == r){
            x[l] = 0LL ;
            return  ;
      }
      int  m = (l + r) >> 1 ;
      make(l , m , t<<1) ;
      make(m+1 , r , t<<1|1) ;
}

void  update(int i , LL c , int l , int r , int t){
      if(l == r){
           x[l] += c ;
           sum[t] += c ;
           if(st.find(x[l]) != st.end()) color[t] = 1 ;
           else                          color[t] = -1 ;
           return ;
      }
      int m = (l + r) >> 1 ;
      if(i <= m) update(i , c , l , m , t<<1) ;
      else       update(i , c , m+1 , r , t<<1|1) ;
      if(color[t<<1] == 1 && color[t<<1|1] == 1) color[t] = 1 ;
      else    color[t] = -1 ;
      sum[t] = sum[t<<1] + sum[t<<1|1] ;
}

LL    ask(int l , int r , int L , int R , int t){
      if(l <= L && R <= r)  return sum[t] ;
      LL s = 0LL ;
      int m = (L + R) >> 1 ;
      if(l <= m) s += ask(l , r , L , m , t<<1) ;
      if(r > m)  s += ask(l , r , m+1 , R , t<<1|1) ;
      return s ;
}

void  change(int l , int  r , int L , int R , int t){
      if(color[t] == 1)  return ;
      if(L == R){
           if(x[L] < 1){
                 x[L] = 1 ;
                 sum[t] = 1 ;
                 color[t] = 1 ;
                 return ;
           }
           int i ;
           for(i = 0 ; i <= 80 ; i++){
                 if(a[i] > x[L]) break ;
           }
           color[t] = 1 ;
           if(x[L] - a[i-1] <= a[i] - x[L])  x[L] = a[i-1] ;
           else     x[L] = a[i] ;
           sum[t] = x[L] ;
           return  ;
      }
      int m = (L + R) >> 1 ;
      if(l <= m)  change(l , r  , L , m , t<<1) ;
      if(r > m)   change(l , r , m+1 , R , t<<1|1) ;
      if(color[t<<1]== 1 && color[t<<1|1] == 1) color[t] = 1 ;
      else    color[t] = -1 ;
      sum[t] = sum[t<<1] + sum[t<<1|1] ;
}

int   main(){
      Fibonacci()  ;
      int n , m , k , a , b ;
      while(cin>>n>>m){
           make(1 , n , 1) ;
           while(m--){
                scanf("%d%d%d" , &k ,&a ,&b) ;
                if(k == 1)
                      update(a , (LL)b , 1 , n , 1) ;
                else if(k == 2){
                      if(a > b) swap(a , b) ;
                      printf("%I64d\n" , ask(a , b , 1 , n , 1)) ;
                }
                else{
                      if(a > b) swap(a , b) ;
                      change(a , b , 1 , n , 1)  ;
                }
           }
      }
      return  0  ;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值