样例没过,悬关*1
查看原帖
样例没过,悬关*1
780514
N1tr0us_Acid楼主2024/5/5 18:06

RT

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 5e5 + 10;

int n, m;
int a[N], tr[N];
int opt, x, y, k;

int lowbit(int x) {
	return x & -x;
}

void upd(int x, int p) {
	for (int i = x; i <= n; i += lowbit(i)) {
		tr[i] += p;
	}
}

int query(int x) {
	int res;
	
	for (int i = x; i > 0; i -= lowbit(i)) {
		res += tr[i];		
	}
	
	return res;
}

signed main (void) {
	cin >> n >> m;
	
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	
	while (m --) {
		cin >> opt;
		
		if(opt == 1) {
			cin >> x >> y >> k;
			
			upd(x, k);
			upd(y + 1, -k);
		}
		
		if(opt == 2) {
			cin >> x;
			
			cout << query(x) + a[x] << endl;
		}
	}
	
	return 0;
}

2024/5/5 18:06
加载中...