Submission #339181

# Submission time Handle Problem Language Result Execution time Memory
339181 2020-12-24T19:12:29 Z FlashGamezzz Divide and conquer (IZhO14_divide) C++17
0 / 100
1 ms 364 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <iostream>
#include <map>

using namespace std;

int n, k, stree[300000] = {};
vector<pair<int, pair<int, int > > > mines;
vector<int> gld, svs; vector<pair<int, int> > nrg;
map<int, int> cc;

void updh(int i, int s, int e, int l, int u, int d) {
	if (s > e || s > u || e < l) {
		return;
	}
	if (s >= l && e <= u) {
		stree[i] = max(stree[i], d); return;
	}
	updh(i*2+1, s, (s+e)/2, l, u, d); updh(i*2+2, (s+e)/2+1, e, l, u, d);
	stree[i] = max(stree[i*2+1], stree[i*2+2]);
}
void updv(int i, int d) {
	updh(0, 0, n-1, i, i, d);
}
int maxh(int i, int s, int e, int l, int u) {
	if (s > e || s > u || e < l) {
		return 0;
	}
	if (s >= l && e <= u) {
		return stree[i];
	}
	return max(maxh(2*i+1, s, (s+e)/2, l, u), maxh(2*i+2, (s+e)/2+1, e, l, u));
}
int maxv(int l, int u) {
	return maxh(0, 0, n-1, l, u);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n;
	for (int i = 0; i < n; i++){
		int a, b, c; cin >> a >> b >> c;
		mines.push_back(make_pair(a, make_pair(b, c)));
	}
	sort(mines.begin(), mines.end());
	int last = 0; gld.push_back(0); nrg.push_back(make_pair(0, 0));
	for (int i = 0; i < n; i++){
		int x = mines[i].first, cnrg = mines[i].second.second, cgld = mines[i].second.first;
		nrg.push_back(make_pair(cnrg+nrg[i].first+last-x, i+1));
		svs.push_back(nrg[i].first-x+last); last = x; gld.push_back(gld[i]+cgld);
	}
	sort(nrg.begin(), nrg.end());
	for (int i = 0; i < n; i++){
		cc[nrg[i].first] = i;
	}
	for (int i = 0; i < n; i++){
		updv(cc[nrg[i].first], nrg[i].second);
	}
	int ans = 0;
	for (int i = 0; i < n; i++){
		ans = max(ans, gld[maxv(cc.lower_bound(svs[i])->second, n)]-gld[i]);
	}
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -