您的位置:首页 > 大数据 > 人工智能

2014 Multi-University Training Contest 3小记

2014-07-29 17:36 288 查看
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  ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: