HDOJ 6012 Lotus and Horticulture

明顯溫度可以離散化,最多10^6個點,由於只要求最終結果,不需要動態更新,所以用前綴和就可以了。比賽的時候寫了線段樹,麻煩了。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

map<int, LL> mpp;
int n;

void work()
{
	mpp.clear(), mpp[0] = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		int l, r, a, b, c;
		scanf("%d%d%d%d%d", &l, &r, &a, &b, &c);
		mpp[0] += c, mpp[l*2] += -c+a, mpp[r*2+1] += -a+b;
	}
	LL ans = 0, t = 0;
	for(auto i : mpp) {
		t += i.second;
		ans = max(ans, t);
	}
	printf("%lld\n", ans);
}

int main()
{
	int _;
	scanf("%d", &_);
	while(_--) work();
	
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章