首页 > 其他 > 详细

2019.9.4 清点人数

时间:2019-09-04 19:38:57      阅读:81      评论:0      收藏:0      [点我收藏+]

树状数组水题(逃

题目传送门

 

裸的树状数组 哪个车厢上下人就更新数据 走到哪个车厢就查

上代码

#include<iostream>
#include<cstdio>
#include<cstring>
#define lowbit(x) x&(-x)
#define int long long
using namespace std;
int n,k,m,p;
char ch;
int c[1000050];
void updata(int i,int x)
{
    while(i<=n)
    {
        c[i]+=x;
        i+=lowbit(i);
    }
}
int query(int i)
{
    int res=0;
    while(i>=1)
    {
        res+=c[i];
        i-=lowbit(i);
    }
    return res;
}
signed main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=k;i++)
    {
        cin>>ch;
        if(ch==A)
        {
            scanf("%lld",&m);
            printf("%lld\n",query(m));
        }
        if(ch==B)
        {
            scanf("%lld%lld",&m,&p);
            updata(m,p);
        }
        if(ch==C)
        {
            scanf("%lld%lld",&m,&p);
            updata(m,-1*p);
        }
    }
    return 0;
}

 

2019.9.4 清点人数

原文:https://www.cnblogs.com/qxds/p/11460919.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!