linuxCE了但windows下通过(急)
查看原帖
linuxCE了但windows下通过(急)
690561
违规用户名690561楼主2024/11/22 19:17

题目 输出信息为:Nothing is compiled: OUTPUT exceeds.

#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e12;
int n, m, opt, l, r, p;
long long a[500005], k;
struct Node {
	long long max_l = -inf, max_r = -inf, sum = -inf, ans = -inf;
} tree[2000005];
void pushup(int p) {
	tree[p].max_l = max(tree[p * 2].max_l, tree[p * 2].sum + tree[p * 2 + 1].max_l);
	tree[p].max_r = max(tree[p * 2 + 1].max_r, tree[p * 2].max_r + tree[p * 2 + 1].sum);
	tree[p].sum = tree[p * 2].sum + tree[p * 2 + 1].sum;
	tree[p].ans = max(max(tree[p * 2].ans, tree[p * 2 + 1].ans), tree[p * 2].max_r + tree[p * 2 + 1].max_l);
	return;
}
void build(int s, int t, int p) {
	if(s == t) {
		tree[p].max_l = a[s];
		tree[p].max_r = a[t];
		tree[p].sum = a[s];
		tree[p].ans = a[s];
		return;
	}
	int mid = (s + t) / 2;
	build(s, mid, p * 2);
	build(mid + 1, t, p * 2 + 1);
	pushup(p);
	return;
}
void update(int s, int t, int p) {
	if(l <= s && t <= r) {
		tree[p].max_l = k;
		tree[p].max_r = k;
		tree[p].sum = k;
		tree[p].ans = k;
		return;
	}
	int mid = (s + t) / 2;
	if(l <= mid) {
		update(s, mid, p * 2);
	}
	if(mid + 1 <= r) {
		update(mid + 1, t, p * 2 + 1);
	}
	pushup(p);
	return;
}
Node find(int s, int t, int p) {
	if(l <= s && t <= r) {
		return tree[p];
	}
	int mid = (s + t) / 2;
	Node ax1, ax2, ax;
	if(r <= mid) {
		return find(s, mid, p * 2);
	}
	if(mid + 1 <= l) {
		return find(mid + 1, t, p * 2 + 1);
	}
	ax1 = find(s, mid, p * 2);
	ax2 = find(mid + 1, t, p * 2 + 1);
	ax.max_l = max(ax1.max_l, ax1.sum + ax2.max_l);
	ax.max_r = max(ax2.max_r, ax1.max_r + ax2.sum);
	ax.sum = ax1.sum + ax2.sum;
	ax.ans = max(max(ax1.ans, ax2.ans), ax1.max_r + ax2.max_l);
	return ax;
}
int main() {
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}
	build(1, n, 1);
	for(int i = 1; i <= m; i++) {
		scanf("%d", &opt);
		if(opt == 1) {
			scanf("%d %d", &l, &r);
			if(l > r) {
				swap(l, r);
			}
			printf("%lld\n", find(1, n, 1).ans);
		} else {
			scanf("%d %lld", &p, &k);
			l = r = p;
			update(1, n, 1);
		}
	}
	return 0;
}
2024/11/22 19:17
加载中...