WA求助(70分)
查看原帖
WA求助(70分)
1438571
Galaxy__H3356楼主2024/12/16 19:53
#include <bits/stdc++.h>
#define int __int128 
using namespace std;

inline int read(){
	int s = 0, w = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){ if(ch == '-') w = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * w;
}
inline void print(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) print(x/10);
	putchar(char(x%10+'0'));
}

int n, m;
int d[500001];//chafen
int a[500001];
int o[500001];//yuanshi
int egg;
int z;
int q, w, e, r;

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

void add(int x, int y) {
	while (x <= n) {
		a[x] += y;
		x += lowbit(x);
	}
}

int ask(int x) {
	egg = 0;
	while (x > 0) {
		egg += a[x];
		x -= lowbit(x);
	}
	return egg;
}


signed main() {
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	n=read(),m=read();
	for (int i = 1; i <= n; i++) {
		o[i]=read();
		d[i] += o[i];
		d[i + 1] -= o[i];
	}
	for (int i = 1; i <= n; i++)
		add(i, d[i]) ;
	for (int i = 1; i <= m; i++) {
		z=read();
		if (z == 2) {
			q=read();
			
		/*	cout << ask(q) << endl;*/
		print(ask(q));
		printf("\n");
		}
		if (z == 1) {
		/*	cin >> w >> e >> r;*/
			w=read();
			e=read();
			r=read();
			add(w, r);
			add(e + 1, -r);
		}
	}
	return 0;
}
2024/12/16 19:53
加载中...