xfstart07
Get busy living or get busy dying
01  #include < iostream >
02   using   namespace  std;
03
04   int  n,m;
05   int  c[ 500010 ] = { 0 };
06   int  x,y,z;
07   char  ch;
08   int  lowbit( int  x){
09       return  x ^ (x & (x - 1 ));
10  }
11   int  getsum( int  x){
12       int  sum = 0 ;
13       while (x){
14          sum += c[x];
15          x -= lowbit(x);
16      }
17       return  sum;
18  }
19   void  modify( int  x, int  s){
20       while (x <= n){
21          c[x] += s;
22          x += lowbit(x);
23      }
24  }
25   int  main()
26  {
27      scanf( " %d%d " , & n, & m);
28      getchar();
29       while (m -- ){
30          ch = getchar();
31           if (ch == ' A ' ){
32              scanf( " %d " , & z);
33              printf( " %d " ,getsum(z));
34          }
35           else   if (ch == ' B ' ){
36              scanf( " %d%d " , & x, & y);
37              modify(x,y);
38          }
39           else {
40              scanf( " %d%d " , & x, & y);
41              modify(x, - y);
42          }
43          getchar();
44      }
45       return   0 ;
46  }






posted on 2009-05-29 23:49 xfstart07 阅读(116) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理