杭电 1166

1166  弄了半天

#include "stdio.h"

struct node
{
int l,r,sum;
}no[3*50005];

int ks[50005];

int t1,t2;

void build_tree(int a,int b,int c)
{
no[c].l = a ;
no[c].r = b ;
if (a == b)
{
no[c].sum = ks[a];
return ;
}
int mid =(a + b) >> 1 ;
build_tree(a , mid , 2*c);
build_tree(mid+1 , b , 2*c+1);
no[c].sum = no[2*c].sum + no[2*c+1].sum;
}

void add_sub(int a,int b,int c)
{
if (a == b )
{
no[c].sum += t2;
return ;
}

int mid = (a + b ) >> 1;
if (t1 <= mid )
{
add_sub(a , mid , 2*c );
}
else
add_sub(mid +1 , b , 2*c+1 );
no[c].sum = no[2*c].sum + no[2*c+1].sum ;
}

int find_tree(int a, int b,int c)
{
if ((no[c].l == a )&& (no[c].r == b ))
{
return no[c].sum;
}
int mid = (no[c].l + no[c].r) >> 1 ;

if (b <= mid)
{
find_tree(a , b , 2*c);
}
else
if (a > mid)
{
find_tree(a , b , 2*c+1);
}
else
return (find_tree(a, mid , 2*c) + find_tree(mid+1 , b , 2*c+1) );
}

int main(int argc, char* argv[])
{
int n,index,cases = 0 ;
char str[10];
scanf("%d",&index);
while (index--)
{
cases++;
scanf("%d",&n);
for (int i =1 ; i <= n ; ++i )
{
scanf("%d",&ks[i]);
}
build_tree(1 , n , 1 );
printf("Case %d:\n",cases);
while (scanf("%s",str))
{
if (str[0] == 'A')
{
scanf("%d%d",&t1,&t2);
add_sub(1, n , 1 );
}
else
if (str[0] == 'S')
{
scanf("%d%d",&t1,&t2);
t2 = 0 - t2 ;
add_sub(1, n, 1);
}
else
if (str[0] == 'Q')
{
scanf("%d%d",&t1,&t2);
printf("%d\n",find_tree(t1 , t2 ,1));
}
else
break;
}
}
return 0;
}



杭电1166敌兵布阵（线段树）

2015-08-20 20:34:47

MySQL数据库-错误1166 Incorrect column name

2017-09-19 19:44:52

数据库--1166错误

2018-02-27 10:01:50

hdu1166 敌兵布阵 线段树 点更新

2016-08-18 23:29:26

关于MySql出现#1166 - Incorrect column name错误

2014-11-25 11:18:13

51NOD_1166 大数开平方

2017-04-24 10:43:58

51Nod-1166-大数开平方

2017-09-05 16:13:39

T1166 求f(x,n)（#Ⅰ- 6 - 2）

2018-03-11 23:04:21

杭电1166

2013-05-18 17:06:19

HDU-1166-敌兵布阵(树状数组)

2012-07-22 07:57:14