• 树状数组解决敌兵布阵~~


    View Code 
    #include <stdio.h>
    #include <string.h>
    int n;
    long long a[50005],f,b[50005];
    char s[10];
    int lowbit (int t)
    {
        return t & ( t ^ ( t - 1 ) );
    }
    int sum(int end)
    {
        int s=0;
        while (end>0)
        {
            s+=b[end];
            end-=lowbit(end);
        }
        return s;
    }
    void plu(int pos ,int num)
    {
        while (pos<=n)
        {
            b[pos]+=num;
            pos+=lowbit(pos);
        }
    }
    int main()
    {
        int T,i,j,t,c;
        scanf("%d",&T);
        t=0;
        while (T--)
        {
            ++t;
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            scanf("%d",&n);
            for (i=1;i<=n;i++)
                scanf("%lld",&a[i]);
            for (i=1;i<=n;i++)
            {
                int x;
                x=lowbit(i);
                while (x--)
                {
                    b[i]+=a[i-x];
                }
            }
            getchar();
            printf("Case %d:\n",t);
            while (scanf("%s",&s) && s[0]!='E')
            {
                scanf("%d%d",&i,&j);
                if (s[0]=='A') plu(i,j);
                else if (s[0]=='S') plu(i,-j);
                else 
                {
                    f=sum(j)-sum(i-1);
                    printf("%lld\n",f);
                }
            }
        }
        return 0;
    当你试图了解你的祖国时,你已踏上了犯罪的路程。
  • 相关阅读:
    Server.MapPath()
    如何系统学习网络攻击技术
    查询数据库中有多少表、视图、存储过程
    测试种类
    linq使用Distinct()
    ASPxPivotGrid隐藏列
    Jenkins:Linux下安装部署步骤
    Jenkins:【测试设计】使用jenkins 插件Allure生成漂亮的自动化测试报告
    Python:Python 自动化测试框架 unittest 和 pytest 对比
    Jenkins:插件安装方式及插件下载地址
  • 原文地址:https://www.cnblogs.com/modiz/p/2972154.html
Copyright © 2020-2023  润新知