Submission #340652

#TimeUsernameProblemLanguageResultExecution timeMemory
340652IZhO_2021_I_want_SilverDivide and conquer (IZhO14_divide)C++14
100 / 100
159 ms11372 KiB
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <set> #include <map> #include <iomanip> #include <cassert> #include <stack> #include <queue> #include <deque> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp>- using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; // template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key (k) : Number of items strictly smaller than k . // find_by_order(k) : K-th element in a set (counting from zero). #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define pb push_back #define ppb pop_back #define mkp make_pair #define F first #define S second #define lb lower_bound #define ub upper_bound #define show(a) cerr << #a <<" -> "<< a <<" " #define nl cerr <<"\n" #define int ll const int N = (1 << 20) - 1; int n, t[N*3], add[N*3], x[N], g[N], d[N], sumd[N], sumg[N]; void push(int v, int tl, int tr) { if (add[v]) { t[v] += add[v]; if (tl < tr) { add[v*2] += add[v]; add[v*2+1] += add[v]; } add[v] = 0; } } void upd(int l, int r, int x, int v=1, int tl=1, int tr=n) { push(v, tl, tr); if (r < tl || tr < l) { return; } if (l <= tl && tr <= r) { add[v] += x; push(v, tl, tr); return; } int tm = (tl + tr) / 2; upd(l, r, x, v*2, tl, tm); upd(l, r, x, v*2+1, tm+1, tr); t[v] = max(t[v*2], t[v*2+1]); } int get(int pos, int v=1, int tl=1, int tr=n) { push(v, tl, tr); if (tl == tr) { return tl; } int tm = (tl + tr) / 2; if (t[v*2+1]+add[v*2+1] >= 0) { return get(pos, v*2+1, tm+1, tr); } else if (t[v*2]+add[v*2] >= 0) { return get(pos, v*2, tl, tm); } return -1; } void solve() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> x[i] >> g[i] >> d[i]; sumg[i] = sumg[i-1] + g[i]; sumd[i] = sumd[i-1] + d[i]; upd(i, i, sumd[i] - x[i]); } int ans = 0; for (int i = 1; i <= n; ++i) { upd(i, n, +x[i]); int j = get(i); if (i <= j) { ans = max(ans, sumg[j] - sumg[i-1]); } upd(i, n, -x[i]-d[i]); } cout << ans; } main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int tests = 1; //cin >> tests; while (tests --) { solve(); } return 0; } /* Just Chalish! */

Compilation message (stderr)

divide.cpp:99:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   99 |  main () {
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...