模板_BIT

#include<bits/stdc++.h>
#define maxn 500005
//#define int long long
using namespace std;
inline int read()
{
    char x = getchar();
    int lin = 0, f = 1;
    while(x < '0' || x > '9')
    {
        if(x == '-') f = -1;
        x = getchar();
    }
    while(x >= '0' && x <= '9')
    {
        lin = (lin << 1) + (lin << 3) + x - '0';
        x = getchar();
    }
    return lin * f;
}
#define PII pair<int,int>
#define fir first
#define sec second
#define ma(a,b) make_pair(a,b)
#define db double
#define inf 123123123
#define lb(x) x&-x
int f[maxn],n,ty,x,y,m;
void add(int x,int val)
{
    while(x < maxn)
    {
        f[x] += val;
        x += lb(x);
    }
}
int query(int x)
{
    int ans = 0;
    while(x)
    {
        ans += f[x];
        x -= lb(x);
    }
    return ans;
}
signed main(){
    n = read(); m = read();
    for(int i = 1; i <= n; i++)
    {
        ty = read();
        add(i,ty);
    }
    for(int i = 1; i <= m; i++)
    {
        ty = read();
        x = read(); y = read();
        if(ty == 1) add(x,y);
        else printf("%d\n",query(y) - query(x - 1));
    }
}

 

posted @ 2018-11-08 09:37  cc123321  阅读(190)  评论(0编辑  收藏  举报