蒟蒻求助!70分
查看原帖
蒟蒻求助!70分
465817
zhengziao楼主2022/5/1 22:24
#include <iostream>
#include <vector>
using namespace std;

long long c[500005];
vector<long long> ans;

int lowbit(int x)
{
    return x&(-x);
}

void update(int L, int r, int v, int n)
{
    for (int i = L; i <= r; i++)
    {
        for (int j = i; j <= n; j += lowbit(j))
        {
            c[j] += v;
        }
    }
}

int getsum(int x)
{
    int ans=0, ans1=0, ans2=0;
    for (int i = x; i >= 1; i-=lowbit(i))
    {
        ans1 += c[i];
    }
    for (int i = x-1; i >= 1; i -= lowbit(i))
    {
        ans2 += c[i];
    }
    ans = ans1-ans2;
    return ans;
}

void recin()
{
    cin.sync();
    cin.clear();
}

int main()
{
    int n, m, v, q, a, b, c; cin >> n >> m;

    recin();

    for (int i = 1; i <= n; i++)
    {
        cin >> v;
        update(i, i, v, n);
    }

    recin();

    for (int i = 1; i <= m; i++)
    {
        cin >> q;
        if (q == 1)
        {
            cin >> a >> b >> c;
            update(a, b, c, n);
        }
        else
        {
            cin >> a;
            ans.push_back(getsum(a));
        }
    }

    vector<long long>::iterator it=ans.begin();
    for (it; it != ans.end(); it++)
    {
        cout << *it << endl;
    }

    return 0;
}

2022/5/1 22:24
加载中...