为什么一直wa0啊QAQ
查看原帖
为什么一直wa0啊QAQ
56856
youngAnswer楼主2020/7/23 16:03

求查错

#include <bits/stdc++.h>

using namespace std;
const int N = 5e4 + 5;
int n, m, x, y, op, a[N];
const int M = - (1 << 63);
struct stree{
	int l, r;
	long long sum = M, rmax = M, lmax = M, dat = M;
}t[N << 2];
inline void build(int p, int l, int r){
	t[p].l = l; t[p].r = r;
	if (l == r){
		t[p].sum = a[l];
		t[p].dat = a[l];
		t[p].lmax = a[l];
		t[p].rmax = a[l];
		return;
	}
	int mid = (l + r) / 2;
	build(p * 2, l, mid);
	build(p * 2 + 1, mid + 1, r);
	t[p].sum = t[p * 2].sum + t[p * 2 + 1].sum;
	t[p].lmax = max(t[p * 2].lmax, t[p * 2].sum + t[p * 2 + 1].lmax);
	t[p].rmax = max(t[p * 2 + 1].rmax, t[p * 2 + 1].sum + t[p * 2].rmax);
	t[p].dat = max(max(t[p * 2].dat, t[p * 2 + 1].dat), t[p * 2].rmax + t[p * 2 + 1].lmax);
}
inline void change(int p, int x, int v){
	if (t[p].l == t[p].r){
		t[p].sum = v;
		t[p].dat = v;
		t[p].lmax = v;
		t[p].rmax = v;
		return;
	}
	int mid = (t[p].l + t[p].r) / 2;
	if (x <= mid) change(p * 2, x, v);
	else change(p * 2 + 1, x, v);
	t[p].sum = t[p * 2].sum + t[p * 2 + 1].sum;
	t[p].lmax = max(t[p * 2].lmax, t[p * 2].sum + t[p * 2 + 1].lmax);
	t[p].rmax = max(t[p * 2 + 1].rmax, t[p * 2 + 1].sum + t[p * 2].rmax);
	t[p].dat = max(max(t[p * 2].dat, t[p * 2 + 1].dat), t[p * 2].rmax + t[p * 2 + 1].lmax);
}
inline stree ask(int p, int l, int r){
	if (l <= t[p].l && r >= t[p].r) return t[p];
	int mid = (t[p].l + t[p].r) / 2;                    
	if (l > mid) return ask(p * 2 + 1, l, r);
	else if (r <= mid) return ask(p * 2, l, r);
	else {
		stree a = ask(p * 2, l, mid), b = ask(p * 2 + 1, mid + 1, y), res;
    	res.sum = a.sum + b.sum;
    	res.lmax = max(a.lmax, a.sum + b.lmax);
    	res.rmax = max(b.rmax, b.sum + a.lmax);
    	res.dat = max(a.rmax + b.lmax, max(a.dat, b.dat));
    	return res;
	}
}
int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	build(1, 1, n);
//	for (int i = 1; t[i].dat != 0; ++i){
//		cout << t[i].l << " " << t[i].r << " " << t[i].dat << " " << t[i].sum << endl;
//	}
	scanf("%d", &m);
	for (int i = 1; i <= m; ++i){
		scanf("%d%d%d", &op, &x, &y);
		if (op == 1){
			printf("%lld\n", ask(1, x, y).dat);
		}
		else change(1, x, y);
	}
	return 0;
}
2020/7/23 16:03
加载中...