zoukankan      html  css  js  c++  java
  • nyist 116 士兵杀敌

    网上资源很多,百度一下你就知道

    代码:

    #include<stdio.h>
    #include<string.h>
    #define N 1000010
    int c[N],a[N];
    int n = 0;
    int l(int i)
    {
        return i&(-i);
    }
    void change(int i,int m)
    {
       int j;
       for(j = i; j <= n; )
       {
           c[j] += m;
           j += l(j);
       }
    }
    int sum(int i)
    {
        int s = 0;
        while(i>0)
        {
            s+=c[i];
            i -= l(i);
        }
        return s;
    }
    int main()
    {
        int m;
        scanf("%d%d",&n,&m);
        memset(c,0,sizeof(c));
        int i;
        for(i =1 ; i <= n; i++ )
           {
               scanf("%d",&a[i]);
               change(i,a[i]);
           }
        while(m--)
         {
             char ch[10];
             int t,k;
             scanf("%s",ch);
             scanf("%d%d",&t,&k);
             if(ch[0]=='A')
                   change(t,k);
              else if(ch[0]=='Q')
                printf("%d\n",sum(k)-sum(t-1));

         }
         return 0;
    }

  • 相关阅读:
    CF 1119 题解
    CF 582 题解
    CF 1098 题解
    CF 1129 题解
    CF 513 题解
    CF 417 D 题解
    ingress nginx遇到502错误,connect() failed (113 Host is unreachable) while connecting to upstream
    MySQL性能剖析
    MySQL的基准测试
    MySQL架构与历史
  • 原文地址:https://www.cnblogs.com/yyroom/p/2781520.html
Copyright © 2011-2022 走看看