zoukankan      html  css  js  c++  java
  • 模板_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
    ",query(y) - query(x - 1));
        }
    }
  • 相关阅读:
    第二章——链表
    第一章:基本概念
    第八章
    画图
    关于写代码时的心态问题
    checked用id选择器找不到怎么办
    this指向问题
    es6箭头函数
    微信小程序——获取步数
    小程序——数据缓存
  • 原文地址:https://www.cnblogs.com/kczno1fans/p/9927301.html
Copyright © 2011-2022 走看看