This commit is contained in:
1 parent
06fa6530a0
commit
f94e8e3dcd
2 files changed
+84
-27
No files matched your search
@@ -1,34 +1,28 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
int n,m;
|
||||
long long tree[500005];
|
||||
long long a[500005];
|
||||
int lowbit(int n){
|
||||
return n&(-n);
|
||||
inline int lowbit(int x) {return x & (-x);};
|
||||
int n, m;
|
||||
int a[500005];
|
||||
int num[500005];
|
||||
void add(int now, int nn) {
|
||||
for(; now <= n; now += lowbit(now)) num[now] += nn;
|
||||
}
|
||||
void modify(int x,long long k)
|
||||
{
|
||||
for(;x<=n;x+=lowbit(x))
|
||||
tree[x]+=k;
|
||||
int query(int now) {
|
||||
int res = 0;
|
||||
for(; now; now -= lowbit(now)) res += num[now];
|
||||
return res;
|
||||
}
|
||||
long long query(int x){
|
||||
int ans;
|
||||
for(;x;x-=lowbit(x))
|
||||
ans=ans+tree[x];
|
||||
return ans;
|
||||
}
|
||||
int main(){
|
||||
scanf("%d%d",&n,&m);
|
||||
for(int i=1;i<=n;++i){
|
||||
scanf("%lld",&a[i]);
|
||||
modify(i,a[i]);
|
||||
}
|
||||
while(m--){
|
||||
int op,x;
|
||||
long long y;
|
||||
scanf("%d%d%lld",&op,&x,&y);
|
||||
if(op==1) modify(x,y);
|
||||
else printf("%lld\n",query(y)-query(x-1));
|
||||
int main() {
|
||||
scanf("%d%d", &n, &m);
|
||||
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), add(i, a[i]);
|
||||
while(m--) {
|
||||
int op, x, y;
|
||||
scanf("%d%d%d", &op, &x, &y);
|
||||
if(op == 1) {
|
||||
add(x, y);
|
||||
} else{
|
||||
printf("%d\n", query(y) - query(x - 1));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user