全re 求调
查看原帖
全re 求调
811570
H_Monkey楼主2024/3/2 11:42
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[600006];
int lowbit(int x){
	return x&(-x);
}
int count(int x){
	int ans = 0;
	if(x != 0){
		ans += a[x];
		x -= lowbit(x);
	}
	return ans;
}
void add(int x, int pos){//在pos的位置加上x 
	while(x <= n){
		a[pos] += x;
		pos += lowbit(pos); 
	}
}
int main(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		int b;
		cin >> b;
		add(b, i);
	}
	while(m--){
		int i, j, k;
		cin >> i >> j >> k;
		if(i == 1){
			add(k, j);
		}else{
			cout << (count(k)-count(j-1)) << endl;
		}
	}
}
2024/3/2 11:42
加载中...