답안 #572842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572842 2022-06-05T11:21:44 Z vovamr 금 캐기 (IZhO14_divide) C++17
100 / 100
137 ms 59184 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) 	(x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }

struct node {
	node *l = nullptr;
	node *r = nullptr;
	ll mx;
	node(ll x = -inf) : mx(x) {}
};
const ll L = -1e14 - 2e9;
const ll R = +1e14 + 2e9;
inline void upd(node *&v, ll vl, ll vr, int pos, ll x) {
	if (!v) v = new node();
	chmax(v->mx, x);
	if (vl == vr) return;
	ll m = vl + vr >> 1;
	if (pos <= m) upd(v->l, vl, m, pos, x);
	else upd(v->r, m + 1, vr, pos, x);
}
inline ll get(node *v, ll vl, ll vr, ll l, ll r) {
	if (!v || l > r) return -inf;
	else if (vl == l && vr == r) return v->mx;
	ll m = vl + vr >> 1;
	ll a = get(v->l, vl, m, l, min(r, m));
	ll b = get(v->r, m + 1, vr, max(l, m + 1), r);
	return max(a, b);
}
node *rt = nullptr;
inline void upd(int pos, ll x) { upd(rt, L, R, pos, x); }
inline ll get(ll l, ll r) { return get(rt, L, R, l, r); }

inline void solve() {
	int n;
	cin >> n;
	ve<ll> x(n), e(n), c(n);
	for (int i = 0; i < n; ++i) cin >> x[i] >> c[i] >> e[i];

	ve<ll> p1(n), p2(n);
	for (int i = 0; i < n; ++i) {
		p1[i] = e[i], p2[i] = c[i];
		if (i) p1[i] += p1[i - 1], p2[i] += p2[i - 1];
	}

	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		ll val = x[i] - (!i ? 0 : p1[i - 1]);
		upd(val, !i ? 0 : -p2[i - 1]);

		chmax(ans, get(val - e[i], R) + p2[i]);
	}
	cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; // cin >> q;
	while (q--) solve();
	cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}

Compilation message

divide.cpp: In function 'void upd(node*&, long long int, long long int, int, long long int)':
divide.cpp:35:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |  ll m = vl + vr >> 1;
      |         ~~~^~~~
divide.cpp: In function 'long long int get(node*, long long int, long long int, long long int, long long int)':
divide.cpp:42:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |  ll m = vl + vr >> 1;
      |         ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 2 ms 1240 KB Output is correct
19 Correct 2 ms 980 KB Output is correct
20 Correct 2 ms 980 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 3 ms 984 KB Output is correct
23 Correct 7 ms 3540 KB Output is correct
24 Correct 7 ms 3540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 2 ms 1240 KB Output is correct
19 Correct 2 ms 980 KB Output is correct
20 Correct 2 ms 980 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 3 ms 984 KB Output is correct
23 Correct 7 ms 3540 KB Output is correct
24 Correct 7 ms 3540 KB Output is correct
25 Correct 5 ms 2004 KB Output is correct
26 Correct 10 ms 4052 KB Output is correct
27 Correct 13 ms 7172 KB Output is correct
28 Correct 68 ms 30832 KB Output is correct
29 Correct 58 ms 31052 KB Output is correct
30 Correct 134 ms 59184 KB Output is correct
31 Correct 125 ms 58008 KB Output is correct
32 Correct 113 ms 58012 KB Output is correct
33 Correct 96 ms 37240 KB Output is correct
34 Correct 110 ms 25548 KB Output is correct
35 Correct 137 ms 51788 KB Output is correct
36 Correct 113 ms 51048 KB Output is correct