• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 20,  comments - 6,  trackbacks - 0
              1 #include<stdio.h>
              2 #include<string.h>
              3 int value[200005];
              4 struct NODE{
              5     NODE *lchild,*rchild;
              6     int left,right;
              7     int sum;
              8 }mem[100001];
              9 int mempos=0;
             10 NODE *makenode()
             11 {
             12     NODE *p=&mem[mempos++];
             13     memset(p,0,sizeof(p));
             14     return p;
             15 }
             16 void update(NODE *root,int id)
             17 {
             18     if(root->right-root->left==1&&(id==root->right||id==root->left))
             19     {
             20         root->sum=value[root->right]+value[root->left];
             21     }else
             22     {
             23         int mid=(root->left+root->right)/2;
             24         if(id>=mid)
             25         update(root->rchild,id);
             26         if(id<=mid)
             27         update(root->lchild,id);
             28         root->sum=root->rchild->sum+root->lchild->sum-value[mid];
             29     }
             30 }
             31 NODE *build(int beg,int end)
             32 {
             33     NODE * root=makenode();
             34     root->left=beg;
             35     root->right=end;
             36     if(end-beg==1)
             37     {
             38         root->sum=value[beg]+value[end];
             39     }else 
             40     {
             41         int mid=(beg+end)/2;
             42         root->lchild=build(beg,mid);
             43         root->rchild=build(mid,end);
             44         root->sum=root->rchild->sum+root->lchild->sum-value[mid];
             45     }
             46     return root;
             47 }
             48 int get(NODE *root,int beg,int end)
             49 {
             50     if(root->left==beg&&root->right==end)
             51     {
             52         return root->sum;
             53     }
             54         int mid=(root->left+root->right)/2;
             55         if(beg>=mid)
             56         {
             57             return get(root->rchild,beg,end);
             58         }else if(end<=mid)
             59         {
             60             return get(root->lchild,beg,end);
             61         }else 
             62         {
             63             int l=get(root->lchild,beg,mid);
             64             int r=get(root->rchild,mid,end);
             65              return l+r-value[mid];
             66         }
             67 }
             68         
             69 int main()
             70 {
             71     int t,n,i,j,k,ss;
             72     int a,b;
             73     int co;
             74     char qus[20];
             75     scanf("%d",&t);
             76         for(co=1;co<=t;co++)
             77         {
             78             printf("Case %d:\n",co);
             79             scanf("%d",&n);
             80             for(i=1;i<=n;i++)
             81             {
             82                 scanf("%d",&value[i]);
             83             }
             84             getchar();
             85             mempos=0;
             86             NODE *root=build(1,n);
             87             while(scanf("%s",qus))
             88             {
             89                 if(strcmp(qus,"End")==0)
             90                 {
             91                     break;
             92                 }
             93                 if(strcmp(qus,"Add")==0)
             94                 {
             95                     scanf("%d%d",&a,&b);
             96                     value[a]+=b;
             97                     update(root,a);
             98                 }
             99                 if(strcmp(qus,"Sub")==0)
            100                 {
            101                     scanf("%d%d",&a,&b);
            102                     value[a]-=b;
            103                     update(root,a);
            104                 }
            105                 if(strcmp(qus,"Query")==0)
            106                 {
            107                     scanf("%d%d",&a,&b);
            108                     ss=get(root,a,b);
            109                     printf("%d\n",ss);
            110                 }
            111             }
            112         }
            113     
            114 }
            115 //寫了一下午,終于用線段樹寫出了1166~ 

            posted on 2009-02-14 16:08 混沌的云 閱讀(222) 評論(0)  編輯 收藏 引用
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(1)

            隨筆檔案

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久亚洲国产精品一区二区| 国产激情久久久久影院老熟女| 日日躁夜夜躁狠狠久久AV| 久久精品人人做人人妻人人玩| 色综合色天天久久婷婷基地| 亚洲国产精品一区二区三区久久| 无码久久精品国产亚洲Av影片 | 久久精品国产精品亚洲毛片| 久久91精品国产91久久麻豆| 久久人人爽人人爽人人片AV麻烦| 久久亚洲欧美国产精品| 久久中文字幕无码专区| 72种姿势欧美久久久久大黄蕉| 久久国产精品免费一区二区三区 | 69国产成人综合久久精品| 久久免费香蕉视频| 精品久久久久中文字幕日本| 久久强奷乱码老熟女网站| 欧美精品一本久久男人的天堂| 色欲av伊人久久大香线蕉影院| 色播久久人人爽人人爽人人片aV| 欧美久久综合性欧美| 久久天堂AV综合合色蜜桃网 | 国内精品久久久久久久97牛牛| 日韩人妻无码一区二区三区久久99| 中文精品久久久久国产网址| 人妻精品久久无码区| 大香伊人久久精品一区二区| 久久91精品国产91久| 久久久国产99久久国产一| 亚洲午夜福利精品久久| 99久久www免费人成精品 | 色综合合久久天天给综看| 免费观看成人久久网免费观看| 久久九九亚洲精品| 精品综合久久久久久97超人| 狠狠色丁香久久综合婷婷| 久久久久免费精品国产| 一本伊大人香蕉久久网手机| 欧美777精品久久久久网| 久久99精品久久久久久野外|