70分玄关求助大佬 qwq 救救孩子吧qwq
查看原帖
70分玄关求助大佬 qwq 救救孩子吧qwq
1195678
wky2011楼主2025/1/24 20:25
#include <bits/stdc++.h>
#define int long long
using namespace std; 

const int maxn = 5e5 + 9;

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

int n, m;
int sum[maxn]; // sum[i] 代表 以i为右端点的那个区间的和。 

int query(int x) {
	int ans = 0;
	for (; x; x -= lowbit(x)) ans += sum[x];
	return ans;
}

void add(int x, int k) {
	for (; x <= n; x += lowbit(x)) sum[x] += k;
}

int aaa[200005];
signed main() {
	scanf("%lld %lld", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &aaa[i]);
		add(i,aaa[i] - aaa[i-1]);
	}
	while (m--) {
		int opt; scanf("%lld", &opt);
		if (opt == 1) {
			int x,y, k;
			scanf("%lld %lld %lld", &x,&y, &k);
			add(x, k); 
			add(y+1,-k);
		}
		if (opt == 2) {
			int x;
			scanf("%lld ", &x);
			
			printf("%lld\n",query(x));
		}
	}
	return 0;
}
2025/1/24 20:25
加载中...