Submission #307714

#TimeUsernameProblemLanguageResultExecution timeMemory
307714kartelDivide and conquer (IZhO14_divide)C++14
100 / 100
323 ms48376 KiB
#include <iostream> #include <stdio.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") #define F first #define S second #define pb push_back #define N +200500 #define M ll(998244353) #define sz(x) (int)x.size() #define re return #define oo ll(1e18) #define el '\n' #define pii pair <int, int> #define all(x) (x).begin(), (x).end() #define arr_all(x, n) (x + 1), (x + 1 + n) //#define vi vector <int> using namespace std; //using namespace __gnu_pbds; //typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef long long ll; typedef long double ld; struct tree{ tree *L, *R; ll mn; tree () { mn = 1e9; L = NULL; R = NULL; } void upd(ll l, ll r, ll ps, ll val) { if (l == r) mn = val; else { ll md = (l + r) / 2ll; if (ps <= md) { if (L == NULL) L = new tree(); L -> upd(l, md, ps, val); } else { if (R == NULL) R = new tree(); R -> upd(md + 1, r, ps, val); } mn = 1e9; if (L != NULL) mn = min(mn, L -> mn); if (R != NULL) mn = min(mn, R -> mn); } } ll get(ll l, ll r, ll tl, ll tr) { if (l > r || tl > tr || l > tr || tl > r) return 1e9; if (l == tl && r == tr) return mn; ll md = (l + r) / 2ll; ll cur_0 = 1e9; ll cur_1 = 1e9; if (L != NULL) cur_0 = L -> get(l, md, tl, min(md, tr)); if (R != NULL) cur_1 = R -> get(md + 1, r, max(md + 1, tl), tr); return min(cur_0, cur_1); } }; tree t; int i, n, x, g, e; ll pf[N], pr, ans; int main() { // ios_base::sync_with_stdio(0); // cin.tie(NULL); // in("divide.in"); // out("divide.out"); // in("input.txt"); // out("output.txt"); cin >> n; // pr[i] - pr[j - 1] >= x[i] - x[j] // pr[i] - x[i] >= pr[j - 1] - x[j] for (i = 1; i <= n; i++) { ll prr = pr; cin >> x >> g >> e; pr += e; pf[i] = pf[i - 1] + g; int j = t.get(0, 2e9, 0, 1e9 + pr - x); if (j == 1e9) j = i; ans = max(ans, pf[i] - pf[j - 1]); t.upd(0, 2e9, 1e9 + prr - x, i); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...