QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#300220#7582. Snowy SmileI_Love_Sonechka#AC ✓2370ms3728kbC++143.1kb2024-01-07 21:23:232024-01-07 21:23:24

Judging History

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

  • [2024-01-07 21:23:24]
  • 评测
  • 测评结果:AC
  • 用时:2370ms
  • 内存:3728kb
  • [2024-01-07 21:23:23]
  • 提交

answer

#include <bits/stdc++.h>
#include <math.h>
			
using namespace std;
	
#ifndef ONLINE_JUDGE
	#define _GLIBCXX_DEBUG
	#define local_shit freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout);
#else
	#define local_shit
#endif
		
// io macros
#define fastio ios::sync_with_stdio(false); cin.tie(nullptr);
#define make_test_shit freopen("inp.txt", "w", stdout);

// c++ short types
#define Int long long
#define vt vector
#define pi pair<int, int>

// code macros
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ins insert
#define mp make_pair

// loops macros
#define each(x, a) for(auto &x: a)

// some functions
template<typename T>
void umax(T &a, const T &b) { a = max(a,b); }
template<typename T>
void umin(T &a, const T &b) { a = min(a,b); }
void whattime() { cout << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; }
template<typename T>
T firsttrue(T l, T r, function<bool(T)> f) {
	while(r - l > 1) {
		T m = (l+r)/2;
		if(f(m)) {
			r = m;
		} else {
			l = m;
		}
	}
	return r;
}
template<typename T>
T lasttrue(T l, T r, function<bool(T)> f) {
	while(r - l > 1) {
		T m = (l+r)/2;
		if(f(m)) {
			l = m;
		} else {
			r = m;
		}
	}
	return l;
}

class segtree {
	struct node {
		Int pref_max, suf_max, sum, max_sum;
		node(Int v = 0) {
			sum = v;
			pref_max = suf_max = max_sum = max(0ll, v);
		}
		friend node merge(node &a, node &b) {
			node c(a.sum+b.sum);
			c.pref_max = max(a.pref_max, a.sum + b.pref_max);
			c.suf_max = max(b.suf_max, b.sum + a.suf_max);
			c.max_sum = max({a.max_sum, b.max_sum, a.suf_max + b.pref_max});
			return c;
		}
	};
public:
	vt<node> t;
	int n;
	segtree(int _n) : n(_n) {
		t.assign(2*n, {0});
	}
	void update(int p, int dx) {
		t[p+n] = {t[p+n].sum + dx};
		for(p+=n; p > 1; p >>= 1) {
			node l = t[p], r = t[p^1];
			if(p & 1) {
				swap(l, r);
			}
			t[p>>1] = merge(l, r);
		}
	}
	Int get(int l, int r) {
		node left = {0}, right = {0};
		for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if(l & 1) {
				left = merge(left, t[l++]);
			}
			if(r & 1) {
				right = merge(t[--r], right);
			}
		}
		return merge(left, right).max_sum;
	}
};

void solver() {
	int n; cin >> n;
	vt<array<int, 3>> points(n);
	for(auto &p: points) {
		for(auto &x: p) {
			cin >> x;
		}
	}
	for(int j = 0; j < 2; ++j) {
		map<int, int> ids;
		for(auto p: points) {
			ids[p[j]];
		}
		int id = 0;
		for(auto &x: ids) {
			x.second = id++;
		}
		for(auto &p: points) {
			p[j] = ids[p[j]];
		}
	}
	long long res = 0;
	for(int w = 1; w <= n; ++w) {
		vt<vt<array<int, 2>>> addends(n);
		for(auto p: points) {
			addends[p[0]].push_back({p[1], p[2]});
			if(p[0] + w < n) {
				addends[p[0]+w].push_back({p[1], -p[2]});
			}
		}
		segtree st(n);
		for(int i = 0; i < n; ++i) {
			for(auto a : addends[i]) {
				st.update(a[0], a[1]);
			}
			res = max(res, st.get(0, n));
		}
	}
	cout << res << '\n';
}

int main()
{
	fastio;
	int tt = 1;
	cin >> tt;
	for(int t = 0; t < tt; ++t) {
    solver();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3484kb

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: 2370ms
memory: 3728kb

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