new file: P3374.cpp
This commit is contained in:
1 parent
f0f909a039
commit
85dd254b3b
1 file changed
+34
@@ -0,0 +1,34 @@
|
||||
#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);
|
||||
}
|
||||
void modify(int x,long long k)
|
||||
{
|
||||
for(;x<=n;x+=lowbit(x))
|
||||
tree[x]+=k;
|
||||
}
|
||||
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));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user