为何输出如此奇特?WA 0分求调
这是程序:
#include<bits/stdc++.h>
using namespace std;
int n,m,c[500005];
int lowbit(int x){
return x&(-x);
}
int sum(int x){
int s=0;
while(x>0){
s+=c[x];
x-=lowbit(x);
}
return s;
}
void change(int x,int y){
while(x<=n){
c[x]+=y;
x+=lowbit(x);
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
int t1;
cin>>t1;
change(i,t1);
}
for(int i=1;i<=m;i++){
int t1,t2,t3;
cin>>t1>>t2>>t3;
if(t1==1) change(t2,t3);
if(t1==2) cout<<sum(t2)-sum(t3-1)<<endl;
}
return 0;
}
这是输入:
5 5
1 5 4 2 3
1 1 3
2 2 5
1 3 -1
1 4 2
2 1 4
这是输出:
-6 -8
Dalao们帮着看看呗。