Submission #172771

# Submission time Handle Problem Language Result Execution time Memory
172771 2020-01-02T15:12:17 Z tselmegkh Divide and conquer (IZhO14_divide) C++14
0 / 100
288 ms 9304 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;

int x[N], g[N], d[N];
bool vis[N];

long long tree[4 * N], lazy[4 * N], pref[N];

void push(int v, int l, int r, int val){
	if(l != r){
		lazy[v * 2] += val;
		lazy[v * 2 + 1] += val;
	}
	tree[v] += val;
	lazy[v] = 0;
}
void update(int v, int l, int r, int ql, int qr, int val){
	if(l > r)return;
	push(v, l, r, lazy[v]);
	if(ql > r || qr < l)return;
	if(ql <= l && qr >= r){
		push(v, l, r, val);
		return;
	}
	int mid = (l + r) / 2;
	update(v * 2, l, mid, ql, qr, val);
	update(v * 2 + 1, mid + 1, r, ql, qr, val);
	tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
}
int get(int v, int l, int r){
	if(l == r)return l;
	int mid = (l + r) / 2;
	if(tree[v * 2] + lazy[v * 2] >= 0){
		return get(v * 2, l, mid);
	}
	return get(v * 2 + 1, mid + 1, r);
}
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x[i] >> g[i] >> d[i];
		pref[i] = pref[i - 1] + g[i];
	}

	long long ans = 0;
	for(int i = 1; i <= n; i++){
		if(i > 1)update(1, 1, n, 1, i - 1, x[i - 1] - x[i]);
		update(1, 1, n, 1, i, d[i]);
		int l = get(1, 1, n);
		ans = max(ans, pref[i] - pref[l - 1]);
	}
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Incorrect 3 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 760 KB Output is correct
2 Correct 24 ms 1272 KB Output is correct
3 Correct 23 ms 1272 KB Output is correct
4 Correct 116 ms 4348 KB Output is correct
5 Correct 131 ms 4652 KB Output is correct
6 Correct 288 ms 9304 KB Output is correct
7 Correct 216 ms 8096 KB Output is correct
8 Correct 222 ms 8288 KB Output is correct
9 Correct 212 ms 8000 KB Output is correct
10 Incorrect 215 ms 8056 KB Output isn't correct
11 Halted 0 ms 0 KB -