HDU 1166敌兵布阵

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1166
初学线段树,本想些个树,写了一半实在是觉得没必要,此题直接用数组模拟,果断AC,1Y~~~
#include < stdio.h >
#include
< string .h >
int  data[ 50003 ];
int  main()
{
    
int T,N,i,cont=1;
    
int cd_1,cd_2,sum;
    
char comd[7]="\0";
    scanf(
"%d",&T);
    
while(T--)
    
{
        scanf(
"%d",&N);
        printf(
"Case %d:\n",cont);
        cont
++;
        
for(i=0;i<N;i++)
            scanf(
"%d",&data[i]);
        scanf(
"%s",comd);
        
while(strcmp(comd,"End")!=0)
        
{
            scanf(
"%d%d",&cd_1,&cd_2);
            
if(comd[0]=='A')
                data[cd_1
-1]+=cd_2;
            
else if(comd[0]=='S')
                data[cd_1
-1]-=cd_2;
            
else if(comd[0]=='Q')
            
{
                sum
=0;
                
for(i=cd_1-1;i<cd_2;i++)
                    sum
+=data[i];
                printf(
"%d\n",sum);
            }

            memset(comd,
0,sizeof(comd));
            scanf(
"%s",comd);
        }

    }

    
return 0;
}

你可能感兴趣的:(HDU 1166敌兵布阵)