0
点赞
收藏
分享

微信扫一扫

一个简单的整数问题


题目:

​​题目链接:​​

题解:

树状数组

#include <bits/stdc++.h>
using namespace std;
long long a[100005],t[100005];
int n;
void add(int x, int k)
{
for(; x <= n; x += x & -x) t[x] += k;
}
long long ask(int x)
{
long long ans = 0;
for(; x; x -= x & -x) ans += t[x];
return ans;
}
int main()
{
int m;
cin>>n>>m;
for(int i = 1; i <= n; i ++ ) cin>>a[i];
while(m -- )
{
char op;
cin>>op;
if(op == 'C')
{
int L, R, d;
cin>>L>>R>>d;
add(L, d);
add(R + 1, -d);
}
else
{
int x;
cin>>x;
cout<<a[x] + ask(x)<<endl;
}
}
return 0;
}


举报

相关推荐

0 条评论