QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578120#7582. Snowy Smileskip2004AC ✓298ms3864kbC++201.5kb2024-09-20 16:44:222024-09-20 16:44:23

Judging History

你现在查看的是最新测评结果

  • [2024-09-20 16:44:23]
  • 评测
  • 测评结果:AC
  • 用时:298ms
  • 内存:3864kb
  • [2024-09-20 16:44:22]
  • 提交

answer

#include<bits/stdc++.h>
namespace rgs = std::ranges;
using std::cin, std::cout;
using ll = long long;
using u64 = unsigned long long;
using db = double;
struct ob {
	int x, y, w;
	auto operator <=> (const ob &) const = default;
};

struct pr {
	ll pre, suf, max, sum;
	void inc(ll v) {
		sum += v, pre = suf = max = std::max(sum, 0ll);
	}
};
pr merge(pr x, pr y) {
	return (pr) {
		std::max(x.pre, x.sum + y.pre),
		std::max(y.suf, x.suf + y.sum),
		std::max({x.max, y.max, x.suf + y.pre}),
		x.sum + y.sum
	};
}
const int N = 2005;
int L;
pr a[N << 3];
void init(int n) {
	L = 2 << std::__lg(n);
	for(int i = 1;i <= L * 2;++i) a[i] = {};
}

void upt(int p, int v) {
	a[p += L].inc(v);
	for(;p >>= 1;)
		a[p] = merge(a[p << 1], a[p << 1 | 1]);
}


void solve() {
	int n; cin >> n;
	std::vector<ob> a(n);
	std::vector<int> vy;
	for(auto & [x, y, w] : a) {
		cin >> x >> y >> w;
		vy.push_back(y);
	}
	sort(a.begin(), a.end());
	rgs::sort(vy);
	ll ans = 0;
	for(int i = 0;i < n;++i) {
		a[i].y = lower_bound(vy.begin(), vy.end(), a[i].y) - vy.begin() + 1;
	}
	for(int i = 0;i < n;++i) {
		if(!i || a[i].x != a[i - 1].x) {
			init(n);
			for(int j = i, k = j;j < n;j = k) {
				for(;k < n && a[k].x == a[j].x;++k) ;
				for(int l = j;l < k;++l) {
					upt(a[l].y, a[l].w);
				}
				ans = std::max(ans, ::a[1].max);
			}
		}
	}
	cout << ans << '\n';
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	int T; cin >> T;
	for(int i = 0;i < T;++i) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3864kb

input:

2
4
1 1 50
2 1 50
1 2 50
2 2 -500
2
-1 1 5
-1 1 1

output:

100
6

result:

ok 2 number(s): "100 6"

Test #2:

score: 0
Accepted
time: 298ms
memory: 3796kb

input:

52
10
30 -1 -40065867
-15 -74 -695603735
-14 3 -847010045
33 -92 -458180374
-88 -86 -488393753
50 -91 -949931576
39 -99 -168684248
-29 64 783067879
14 -5 -104144786
-67 90 492127865
10
-29 -70 151800541
54 41 -677722362
-85 -72 766300892
-47 -90 -74384884
-12 -56 679506148
0 -41 -30038154
-4 -6 -254...

output:

1275195744
2084179225
1734353870
1018976777
2591083202
1309403622
2358891488
2143566532
1602649268
2112317422
1470851645
2423431804
2209082718
1571719735
1313345276
2039708041
1526772930
1368470878
866267413
1826546180
1878414495
1706604892
1822460963
1942258759
2943744963
2090539403
666502909
14660...

result:

ok 52 numbers