Submission #332120

#TimeUsernameProblemLanguageResultExecution timeMemory
332120Valera_GrinenkoDivide and conquer (IZhO14_divide)C++17
100 / 100
51 ms6892 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include <iostream> #include <fstream> #include <algorithm> #include <vector> #include <set> #include <stack> #include <map> #include <unordered_map> #include <iomanip> #include <cmath> #include <queue> #include <bitset> #include <numeric> #include <array> #include <cstring> #include <random> #include <chrono> #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) typedef long long ll; typedef long double ld; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template<class T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 1e5 + 42; ll n, ans = 0; ll pe[N], pg[N], st[(N << 2)]; void upd(int pos, ll x, int l, int r, int ti) { if(l == r) { st[ti] = x; return; } if(pos <= ((l + r) >> 1)) upd(pos, x, l, ((l + r) >> 1), (ti << 1)); else upd(pos, x, ((l + r) >> 1) + 1, r, (ti << 1) + 1); st[ti] = max(st[(ti << 1)], st[(ti << 1) + 1]); } int fnd(ll x, int l, int r, int ti) { if(l == r) return l; if(st[(ti << 1)] >= x) return fnd(x, l, ((l + r) >> 1), (ti << 1)); return fnd(x, ((l + r) >> 1) + 1, r, (ti << 1) + 1); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) { ll x, g, e; cin >> x >> g >> e; pe[i] = pe[i - 1] + e; pg[i] = pg[i - 1] + g; upd(i, x - pe[i - 1], 1, n, 1); int pos = fnd(x - pe[i], 1, n, 1); ans = max(ans, pg[i] - pg[pos - 1]); } cout << ans; return 0; } /* */

Compilation message (stderr)

divide.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...